nexcess / magento-turpentine

A Varnish extension for Magento.
GNU General Public License v2.0
519 stars 253 forks source link

Customer specific prices are cached #1535

Open onigunn opened 5 years ago

onigunn commented 5 years ago

Customer specific Product Prices

We got a store with customers all over the world each customer has depending on his billing country different tax rates. So product prices are different if customers are signed in. Currently varnish always delivers the first cached version of a product page. My first approach was to extend vcl_hash to include a custom cookie, which is set on customer login/logout. I've added following to the default.vcl

sub vcl_hash {

    # default implementation

    if (req.http.Cookie ~ "magento_country=") {
        std.log("hash_data - country cookie: " + regsub(req.http.Cookie, "^.*?magento_country=([^;]*);*.*$", "\1"));
        hash_data(regsub(req.http.Cookie, "^.*?magento_country=([^;]*);*.*$", "\1"));
    } else {
        std.log("no country cookie found, so we fallback to de");
        hash_data("de");
    }

    std.log("vcl_hash end return lookup");
    return (lookup);
}

Varnish still delivers first cached version instead of a different one based on the hash. vcl_log states, that the cookie is detected and added to the hash. Anyone an idea why I don't get another version?

mabigo commented 5 years ago

same issue. I tried a different approach, by bypassing cache based on cookie via pass/pipe on top of vcl_recv().

if (req.http.Cookie ~ "pricegroup=") { return (pipe); }

Yet, still the first version/price that was requested is delivered regardless of cookie being set. i also noticed, whenever I clean up the esi cache in admin, I get the correct first response.