Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a broken caching strategy #7

Open
wants to merge 4 commits into
base: jfb/1-3-stable/lineitem-discounts-fixes2
Choose a base branch
from

Conversation

rymai
Copy link

@rymai rymai commented Oct 5, 2018

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
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 <[email protected]>
@rymai rymai force-pushed the rymai/1-3-stable/lineitem-discounts-fixes3 branch from 19f5923 to 1792604 Compare October 5, 2018 15:58
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