Magento Multi laguage shop with varnish

How a multilingual Magento shop works with varnish. Is there any configuration in the varnish, so we can create a cache base for cookies?

+5
source share
2 answers

If you are not opposed to languages ​​located at different URLs, Turpentine can handle this for you: https://github.com/nexcess/magento-turpentine/issues/36

If you want them to behave like they do out of the box, keep going.

You need to change the way you create varnish in VCL Link: https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers

, cookie , Magento . ( : http://demo.magentocommerce.com) , , Varnish cookie , , ,

- cookie, URL- :

sub vcl_hash {
        hash_data(req.url);
        hash_data(req.http.host);

        if (req.http.Cookie ~ "(?:^|;\s*)(?:store=(.*?))(?:;|$)"){
                hash_data(regsub(req.http.Cookie, "(?:^|;\s*)(?:store=(.*?))(?:;|$)"));
        }

        return (hash);
}

, , VCL cookie

- cookie , X-Mage-Lang:

sub vcl_fetch {
    #can do this better with regex
    if (req.http.Cookie ~ "(?:^|;\s*)(?:store=(.*?))(?:;|$)"){
        if (!beresp.http.Vary) { # no Vary at all
            set beresp.http.Vary = "X-Mage-Lang";
        } elseif (beresp.http.Vary !~ "X-Mage-Lang") { # add to existing Vary
            set beresp.http.Vary = beresp.http.Vary + ", X-Mage-Lang";
        }
    }
    # comment this out if you don't want the client to know your classification
    set beresp.http.X-Mage-Lang = regsub(req.http.Cookie, "(?:^|;\s*)(?:store=(.*?))(?:;|$)");
}

: https://github.com/varnish/varnish-devicedetect/blob/master/INSTALL.rst

Mage_Core_Model_App, cookie "store". Magento CE 1.7 _checkCookieStore:

protected function _checkCookieStore($type)
{
    if (!$this->getCookie()->get()) {
        return $this;
    }

    $store = $this->getCookie()->get(Mage_Core_Model_Store::COOKIE_NAME);
    if ($store && isset($this->_stores[$store])
        && $this->_stores[$store]->getId()
        && $this->_stores[$store]->getIsActive()) {
        if ($type == 'website'
            && $this->_stores[$store]->getWebsiteId() == $this->_stores[$this->_currentStore]->getWebsiteId()) {
            $this->_currentStore = $store;
        }
        if ($type == 'group'
            && $this->_stores[$store]->getGroupId() == $this->_stores[$this->_currentStore]->getGroupId()) {
            $this->_currentStore = $store;
        }
        if ($type == 'store') {
            $this->_currentStore = $store;
        }
    }
    return $this;
}

$_SERVER ['X-Mage-Lang'] cookie

+5

Varnish Config,

if(beresp.http.Set-Cookie) {
     return (hit_for_pass); 
}
+1

All Articles