BACKGROUND
Magento has the product details page accessible at catalog/product/view/id/{product_id}. It is being hosted on magento cloud so fastly is involved. There are different customer group and each customer group get to see different prices on the product details page. I will usually open two tabs, and on one tab, I will log out of an account that belongs to customer associated with customer group A, then login to an account that belongs to a customer associated with customer group B. Every time I do this, all I need to do is refresh the second tab containing the product details page and the price will change. THIS IS FINE AND THIS IS THE EXPECTED BEHAVIOR
THE ISSUE
I am now in a situation where I need to be able to remove access to a product from a certain customer group in the Magento admin form in the backend and as soon as this is done, a customer belonging to that customer group should no longer be able to access that product page in the frontend upon refreshing assuming the page is already opened in his/her browser. This is proving difficult to do.
Please note that this code works in my development environment and Varnish is also enabled and works in my development environment. Fastly just seem to cache differently IN magento cloud staging environment.
THINGS I HAVE DONE
I have added my own additional tag to X-Magento-Tag by adding a block that implements Magento\Framework\DataObject\IdentityInterface
. This Tag is a concatenation of the customer group id and the access status to the product being loaded. If access is revoked, status is 0, otherwise, status is 1.
I have added a before
plugin to Magento\Framework\App\Http\Context::getVaryString()
and this before
plugin also adds the same concatenation of the customer group id and the access status. I believe this is how fastly uniquely Identifies each cached version of a page.
NONE OF THESE HAVE WORKED.
MY QUESTIONS
If fastly works so well when I switch user accounts, why won't it work when additional context need to be factored in?
How do I make fastly check if the user still have access rights to that product page before page is served to web user?
How does fastly know when the current user session have changed? Perhaps I can apply same approach to access revocation.