-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
In a multi-channel setup, an incorrect cached active tax zone is applied.
To Reproduce
Steps to reproduce the behavior:
-
npx @vendure/create my-shop-issue-3681
-
Given
Default channel

- Create
Demo channel
and set default tax and shipping zone to Asia

- Given
Standard Tax Asia

- Update
Standard Tax Europe
and set rate to 21%

- Add product to demo-channel


- Rebuild products search index

- Query default-channel shop-api search and note the price with tax is correct

- Query demo-channel shop-api search and note the price with tax is incorrect

Expected behavior
It is expected that the indexed products will have a tax rate applied that conforms to the channel's tax zone.
Test Environment:
- @vendure/core version: 3.3.7
- Nodejs version: v20.19.0
- Database: postgres:16-alpine
Additional context
I believe the Active Tax Zone
request cache key is not integrity safe. This causes integrity to depend on cache invalidation, for example, when looping through channels during product reindexation.
In the short term, I believe the Active Tax Zone
cache keys for both ProductPriceApplicator applyChannelPriceAndTax
and OrderCalculator applyPriceAdjustments
could be as follows to resolve the issue:
private getCacheKey(channel: Channel, order?: Order) {
return {
code: 'ActiveTaxZone',
integrity: {
channelId: channel.id,
countryCode: order?.shippingAddress?.countryCode,
},
};
}
In the long term, I believe it would be beneficial for the implemented Tax Zone Strategy itself to be responsible for its caching logic. I believe it's good practice for the consumers of the strategy to be able to clear the cache, and even to disable caching entirely.
The approach used in this repository might be of interest in designing the cache logic: https://github.com/joshuaslate/type-cacheable