summaryrefslogtreecommitdiff
path: root/lib/super_good
diff options
context:
space:
mode:
Diffstat (limited to 'lib/super_good')
-rw-r--r--lib/super_good/solidus_taxjar.rb2
-rw-r--r--lib/super_good/solidus_taxjar/tax_calculator.rb18
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb
index ef9497d..818947d 100644
--- a/lib/super_good/solidus_taxjar.rb
+++ b/lib/super_good/solidus_taxjar.rb
@@ -26,6 +26,6 @@ module SuperGood
}
self.taxable_address_check = ->(address) { true }
self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" }
- self.line_item_tax_label_maker = ->(taxjar_line_item) { "Sales Tax" }
+ self.line_item_tax_label_maker = ->(taxjar_line_item, spree_line_item) { "Sales Tax" }
end
end
diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb
index 91ff6c0..5052814 100644
--- a/lib/super_good/solidus_taxjar/tax_calculator.rb
+++ b/lib/super_good/solidus_taxjar/tax_calculator.rb
@@ -35,12 +35,18 @@ module SuperGood
def line_item_taxes
@line_item_taxes ||=
- taxjar_breakdown.line_items.map do |line_item|
+ taxjar_breakdown.line_items.map do |taxjar_line_item|
+ spree_line_item_id = taxjar_line_item.id.to_i
+
+ # Searching in memory because this association is loaded and most
+ # orders aren't going to have a huge number of line items.
+ spree_line_item = order.line_items.find { |li| li.id == spree_line_item_id }
+
Spree::Tax::ItemTax.new(
- item_id: line_item.id.to_i,
- label: line_item_tax_label(line_item),
+ item_id: spree_line_item_id,
+ label: line_item_tax_label(taxjar_line_item, spree_line_item),
tax_rate: tax_rate,
- amount: line_item.tax_collectable,
+ amount: taxjar_line_item.tax_collectable,
included_in_price: false
)
end
@@ -141,8 +147,8 @@ module SuperGood
)
end
- def line_item_tax_label(taxjar_line_item)
- SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item)
+ def line_item_tax_label(taxjar_line_item, spree_line_item)
+ SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item, spree_line_item)
end
end
end