Skip to content

Commit

Permalink
Utilize variant tax category when calculating taxes if possible
Browse files Browse the repository at this point in the history
In the default tax_calculator, this change ensures that the variant’s
current tax_category is considered when calculating taxes.

In the case of the item_rates method, only line_item items will have
this method, so it is accessed with `try` first, with a fallback to
without `variant_`

Co-authored-by: Adam Mueller <[email protected]>
  • Loading branch information
harmonymjb and adammathys committed Jan 7, 2025
1 parent 3a39c53 commit 5768c53
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/tax/tax_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def rates_for_item(item)
@rates_for_item ||= Spree::TaxRate.item_level.for_address(item.order.tax_address)

@rates_for_item.select do |rate|
rate.active? && rate.tax_categories.map(&:id).include?(item.tax_category_id)
rate.active? && rate.tax_categories.map(&:id).include?(item.try(:variant_tax_category_id) || item.tax_category_id)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/tax_calculator/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def calculate_rates(item)
# @return [Array<Spree::TaxRate>] rates that apply to an order
def rates_for_order
tax_category_ids = Set[
*@order.line_items.map(&:tax_category_id),
*@order.line_items.map(&:variant_tax_category_id),
*@order.shipments.map(&:tax_category_id)
]
rates = Spree::TaxRate.active.order_level.for_address(@order.tax_address)
Expand Down

0 comments on commit 5768c53

Please sign in to comment.