Skip to content

Fix a broken caching strategy - #7

Open
rymai wants to merge 4 commits into
boomerdigital:jfb/1-3-stable/lineitem-discounts-fixes2from
rymai:rymai/1-3-stable/lineitem-discounts-fixes3
Open

Fix a broken caching strategy#7
rymai wants to merge 4 commits into
boomerdigital:jfb/1-3-stable/lineitem-discounts-fixes2from
rymai:rymai/1-3-stable/lineitem-discounts-fixes3

Conversation

@rymai

@rymai rymai commented Oct 5, 2018

Copy link
Copy Markdown
Fix a broken caching strategy

Previously, only the tax amount for the last line item would be used to
calculate the taxes for an order.

For instance if I had an item with a tax of 0.5 and an item with a tax of
1.2. The total tax would have been 2 * 1.2.

Now, we cache the whole TaxJar response and properly pick the correct
tax amount for each item. The cache key for the TaxJar response should
make sure that any update to the items, address, or shipping will result
in a new cache key, and thus an new TaxJar call to fetch up-to-date
amounts.

# the taxjar_line_item is a hash of the API response
# the line_item is the Spree::LineItem object
line_item = Spree::LineItem.find(taxjar_line_item.id)
res = taxjar_line_item.tax_collectable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we would always use the last item's tax amount.

Previously, only the tax amount for the last line item would be used to
calculate the taxes for an order.

For instance if I had an item with a tax of 0.5 and an item with a tax of
1.2. The total tax would have been 2 * 1.2.

Now, we cache the whole TaxJar response and properly pick the correct
tax amount for each item. The cache key for the TaxJar response should
make sure that any update to the items, address, or shipping will result
in a new cache key, and thus an new TaxJar call to fetch up-to-date
amounts.

Signed-off-by: Rémy Coutable <remy@rymai.me>
@rymai
rymai force-pushed the rymai/1-3-stable/lineitem-discounts-fixes3 branch from 19f5923 to 1792604 Compare October 5, 2018 15:58
rymai added 2 commits October 15, 2018 09:44
Signed-off-by: Rémy Coutable <remy@rymai.me>
Signed-off-by: Rémy Coutable <remy@rymai.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants