Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Product variant pages generated using ProductVariation->toUrl()
don't have the right cache contexts. Having dynamic_page_cache enabled, always the same product variant is being displayed.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2884083-product-entity-cache-contexts-7.patch | 811 bytes | mglaman |
| |||
#3 | commerce-product-variation-cache.patch | 838 bytes | bradjones1 |
Comments
Comment #2
Lukas von BlarerComment #3
bradjones1So in my testing the issue seems to be that the render array's cache metadata does not include the 'v' query string key, and so the fields relating to the current product variation from the context are cached regardless of that value. This patch adds the cache context to the build array.
Not sure if test coverage in Commerce exists/needs to change to cover this?
Comment #4
mglamanThat is the correct approach. I thought there was an open issue for this already. Good patch. We can write tests for it ensure cache busting.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedLet's add a test and wrap this up.
Comment #6
mglamanActually, I'm pretty sure we can define this on the product class itself.
Comment #7
mglamanThis doesn't add tests, but it puts the cache context on the product entity so it is always available and bubbles up.
Comment #9
bojanz CreditAttribution: bojanz at Centarro commentedCommitted #7 since it's release day, renaming the issue so that it receives the test.
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedReverting the title, having a test for this one-liner no longer feels like good use of our time.