0

I am working on a requirement to add a custom parameter in the configurable product page URL. This will have the simple SKU to preselect the color in the swatches, something like this:

https://site.test.com/product-page-url.html?v=simplesku

The user requires this way because these URLs will be generated by the marketing team and need an easy way to create a URL to each simple and send in the marketing communication (for example, newsletter or Facebook posts).

The customization works fine, and it selects the simple product in the swatches specified in the URL without a problem. However, this selection seems to be caching. So, for example, if you first go to this URL:

https://site.test.com/product-page-url.html?v=simplesku

It shows the correct color. But if you next go to:

https://site.test.com/product-page-url.html?v=simplesku2

https://site.test.com/product-page-url.html?v=simplesku3

https://site.test.com/product-page-url.html?v=simplesku4

Or even without the parameter in the URL:

https://site.test.com/product-page-url.html

The result is the same. The page shows the first color and ignores the parameter in all the subsequent attempts. Is it a way to add this custom parameter to prevent to be caching, and with that, each URL with a different value in it generates a different page result?

1 Answer 1

0

If you are using PHP to select the default swatch from the URL parameter, the full page cache will always cache the first instance of the request. This is because all of these URLs:

https://site.test.com/product-page-url.html?v=simplesku

https://site.test.com/product-page-url.html?v=simplesku2

https://site.test.com/product-page-url.html?v=simplesku3

https://site.test.com/product-page-url.html?v=simplesku4

...share the same cache key.

You can read up on how to customize an existing cache key, with overview info at https://developer.adobe.com/commerce/php/development/cache/partial/

That said, I'd recommend to pre-select the swatch with something like a JavaScript or UI Component, as that wouldn't affect the full page cache, and you wouldn't have to touch cache keys or worry about cache invalidation. Also, it will be more optimal, as really all of the above URLs should probably share a common cache, and modifying the cache keys would be inefficient, as that would require a separate cache file for each query combination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.