cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 Varnish 4, group/special pricing

Magento2 Varnish 4, group/special pricing

I'm stumped on this one and can't find a solution; there are similar questions/solutions but for Magento 1.x

 

We've had Varnish 4 working great since M2.0.1 - that is, without using group pricing.  Everything works fine (varnish purges, caches etc) and fast but as soon as a customer from a special group logs in, their prices are cached only to confuse the next visitor when they check out (aka go to a secured portion of the site).

 

For example: standard visitors pay $20/unit, Gold customers $15. If a Gold customer logs in, views products etc, the next visitor will automatically see $15/unit instead of $20. When this next visitor goes to the cart it shows the proper pricing of $20 which is an issue.

 

I don't know enough programmatically what I'm looking for so my question is, could this be a theme/template issue where price blocks are supposed to be a cacheable/non-cacheable block? And/or has anyone experienced this when using group pricing AND regular visitor pricing?

 

Any pointers would be appreciated.

4 REPLIES

Re: Magento2 Varnish 4, group/special pricing

Disregard this message - I can't delete my own post. I disabled FPC and all works as it should.

Re: Magento2 Varnish 4, group/special pricing

Hi, I'm having the same issue here.
Magento 2.1.3.
Disable the FPC is not best solution I think. Because it will just make the site heavy to load. So we should not disable the FPC on live site.
Does anyone have a solution for this issue?

Re: Magento2 Varnish 4, group/special pricing

@yosef_kurniawan

 

you need to do customer group wise caching.

 

Re: Magento2 Varnish 4, group/special pricing

The Vary HTTP header is used to allow a cache to distinguish between different types of content.

However, Magento 2 also has additional Vary-like behaviour that allows store/customer specific content to be differentiated in the cache. This is achieved by setting a cookie called X-Magento-Vary, which is then used as part of the VCL hash.

...
sub vcl_hash {
    if (req.http.cookie ~ "X-Magento-Vary=") {
        hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
    }
    ...

 

Check your VCL for this rule. Do you have one varnish or many?