Smile-SA / magento2-module-retailer

14 stars 29 forks source link

Cache refreshment #1

Closed AymericJoubert closed 7 years ago

AymericJoubert commented 8 years ago

The add-to-cart button does not appear on product page after choosing retailer and pickup date.

Steps to reproduce :

We are working with varnish, is there some headers to add to the varnish conf ?

romainruaud commented 8 years ago

There is two main points to check if you are using Varnish :

This can be something like this (untested) :

into the vcl_recv function :

    if (req.http.Cookie && req.http.Cookie ~ "(?i)retailer_id=") {
        set req.http.X-Retailer-Id = regsub(req.http.Cookie, "(?i).*retailer_id=([^;]+).*", "\1");
        # Ignore it if empty
        if (req.http.X-Retailer-Id ~ "^ *$") { unset req.http.X-Retailer-Id; }
    }
    if (req.http.Cookie && req.http.Cookie ~ "(?i)pickup_date=") {
        set req.http.X-Pickup-Date = regsub(req.http.Cookie, "(?i).*pickup_date=([^;]+).*", "\1");
        # Ignore it if empty
        if (req.http.X-Pickup-Date ~ "^ *$") { unset req.http.X-Pickup-Date; }
    }

And on the vcl_hash function :

    if (req.http.X-Retailer-Id) {
        hash_data(req.http.X-Retailer-Id);
    }
    if (req.http.X-Retailer-Id) {
        hash_data(req.http.X-Retailer-Id);
    }
AymericJoubert commented 7 years ago

Here are the headers i added :

In vcl_recv :

if (req.http.Cookie && req.http.Cookie ~ "smile_retailer_id=") {
    set req.http.X-Retailer-Id = regsub(req.http.Cookie, ".*smile_retailer_id=([^;]+).*", "\1");
    # Ignore it if empty
    if (req.http.X-Retailer-Id ~ "^ *$") { unset req.http.X-Retailer-Id; }
}

if (req.http.Cookie && req.http.Cookie ~ "smile_retailer_pickupdate=") {
    set req.http.X-Pickup-Date = regsub(req.http.Cookie, ".*smile_retailer_pickupdate=([^;]+).*", "\1");
    # Ignore it if empty
    if (req.http.X-Pickup-Date ~ "^ *$") { unset req.http.X-Pickup-Date; }
}

In vcl_hash :

if (req.http.X-Retailer-Id) {
    hash_data(req.http.X-Retailer-Id);
}

if (req.http.X-Pickup-Date) {
    hash_data(req.http.X-Pickup-Date);
}

This works, we now have a cache by retailer and pickup date. Thanks