- 🇺🇸United States nicxvan
I am having this issue as well, I am not scheduling any of them in the future.
I will test disabling Internal Dynamic Page Cache and report back as well.
- 🇺🇸United States nicxvan
It's more severe on views pages. Changing roles for a user will update the product page but not a view of products.
I am loading the view with a render array in a preprocess.
It only seems to be when a user's role changes, not when a different user loads the page.
- 🇺🇸United States nicxvan
To make my use case more explicit I have four price lists and each one is tied to a role. I suspect roles are not added to the caching context properly when listed in a view.
- 🇳🇱Netherlands joshahubbers
We experience the same problem, but prices are cached across users. So if a user with a discount opens the page first, a user without the discount will also see the discounted price also.
- 🇳🇱Netherlands joshahubbers
We added 'user.roles' in our services.yml, like this:
required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions', 'user.roles']
But I think this should be added as a cache context explicitly to the display as a better fix.
- 🇳🇱Netherlands joshahubbers
Another fix is to add the 'user.roles' cache context to the productVariation entity:
File: commerce/modules/product/src/Entity/ProductVariation.php
/** * {@inheritdoc} */ public function getCacheContexts() { return Cache::mergeContexts(parent::getCacheContexts(), ['store', 'user.roles']); }
I will have a look at the commerce issue queue to check if there is an issue for this.
- 🇮🇱Israel jsacksick
In this case I believe the right fix would be for the PriceCalculatedFormatter to add a cache contex on the user role.
It currently has:'#cache' => [ 'tags' => $purchasable_entity->getCacheTags(), 'contexts' => Cache::mergeContexts($purchasable_entity->getCacheContexts(), [ 'languages:' . LanguageInterface::TYPE_INTERFACE, 'country', ]), ],
- 🇮🇱Israel jsacksick
This is why updating the ProductVariation cache contexts works.
- 🇳🇱Netherlands joshahubbers
I also tried to add a hook_ENTITY_TYPE_build_defaults_alter (hook_product_variation_build_defaults_alter) to add the user.role context. The strange thing is that the cache context is added, but I think that later in the process somewhare a call to getCacheContexts is done, and then the original cache context is restored. But I did not have the time to confirm my feeling.