Skip to content

Incorrect cached active tax zone #3681

@hans-rollingridges-dev

Description

@hans-rollingridges-dev

Describe the bug
In a multi-channel setup, an incorrect cached active tax zone is applied.


To Reproduce
Steps to reproduce the behavior:

  1. npx @vendure/create my-shop-issue-3681

  2. Given Default channel

Image
  1. Create Demo channel and set default tax and shipping zone to Asia
Image
  1. Given Standard Tax Asia
Image
  1. Update Standard Tax Europe and set rate to 21%
Image
  1. Add product to demo-channel
Image Image
  1. Rebuild products search index
Image
  1. Query default-channel shop-api search and note the price with tax is correct
Image
  1. Query demo-channel shop-api search and note the price with tax is incorrect
Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions