Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/app/models/spree/tax_calculator/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def initialize(order)
#
# @return [Spree::Tax::OrderTax] the calculated taxes for the order
def calculate
ActiveRecord::Associations::Preloader.new(records: order.line_items, associations: {variant: :product}).call

Spree::Tax::OrderTax.new(
order_id: order.id,
order_taxes: order_rates,
Expand Down
13 changes: 13 additions & 0 deletions core/spec/models/spree/tax_calculator/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,18 @@
expect(order_tax.label).to eq "Flat Book Fee"
end
end

context "with multiple line items" do
Comment thread
ikraamg marked this conversation as resolved.
before do
2.times do
order.contents.add(FactoryBot.create(:product, tax_category: books_category).master)
Comment thread
ikraamg marked this conversation as resolved.
end
order.reload
end

it "loads line item variants in a single query" do
Comment thread
ikraamg marked this conversation as resolved.
expect { calculator.calculate }.to make_database_queries(matching: /from .spree_variants..*\bid. IN \(/im, count: 1)
Comment thread
ikraamg marked this conversation as resolved.
end
end
end
end
Loading