When fetching products and variations the returned data may be incorrect. This can happen when the store context changes, especially in an API environment.

Product and ProductVariation should add the `store` cache context in their returned getCacheContexts values.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
1.07 KB

This definitely needs some tests to prove render cache is bypassed on store context. An example is price resolving by store.

mglaman’s picture

+++ b/modules/product/src/Entity/Product.php
@@ -262,6 +262,13 @@ class Product extends CommerceContentEntityBase implements ProductInterface {
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheContexts() {
+    return Cache::mergeContexts(parent::getCacheContexts(), ['store']);
+  }

🤦🏼‍♂️this is already overridden for the variations query param.

mglaman’s picture

Here's an updated patch with tests.

mglaman’s picture

Issue tags: -Needs tests

Status: Needs review » Needs work

The last submitted patch, 4: 3105238-tests-only.patch, failed testing. View results

mglaman’s picture

Status: Needs work » Needs review
bojanz’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

mglaman’s picture

Tagging two customers involved in this patch.

  • mglaman committed 1b123cd on 8.x-2.x
    Issue #3105238 by mglaman, bojanz: Products and variations must have the...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.