PHOENIX-MEDIA / Magento-PageCache-powered-by-Varnish

Community version which is available on Magento Connect (http://www.magentocommerce.com/magento-connect/pagecache-powered-by-varnish.html)
89 stars 49 forks source link

Still issue with add to cart - the second time it works #38

Open musab1 opened 8 years ago

musab1 commented 8 years ago

Hi all

I've read all the READMEs and all the posts in the other issues (and tryed/implemented everything out).

I have the problem (since this form_key disaster) that the add to cart still doesnt work.

The first time i try to add something to the card it shows an empty cart - and the EXTERNAL_NO_CACHE cookie get set (and then afterwards it works, becouse its bypassing Varnish becouse of the cookie).

I can not figure out what the problem is becouse the PAGECACHE_FORMKEY cookie is getting set right, and the html sourcecode shows the same key. so its not like this esi tags didnt get replaced.

musab1 commented 8 years ago

a small Update: when i set the external_no_cache cookie manualy, it still doesnt work. so it must be something else - related to this form_keys or whatever.

Guard1an commented 8 years ago

Was having the same issue, but it disappeared after I removed tricks I've done with cookies in default.vcl. Check whether PAGECACHE_FORMKEY cookie is really passed to backend (log cookies in checkout/cart/add controller action)

BTW: I found out that Varnish relies on Vary: User-Agent headers so removing them will make your caching proxy not to clone cache of the same content for different browsers.

Try to enable module debug option and check X-Cache* headers in different browsers. After baning the cache and accessing the same url from different browsers you will see 0 hits and X-Cache:MISS. That happens because Varnish relies on Vary: User-Agent header sent by Magento. If your application doesn't rely on User-Agent (content is the same on all devices and depends on URL or session only) you can solve User-Agent issue by adding the following lines to sub vcl_recv of default.vcl

    if (beresp.http.Vary ~ "User-Agent") {
        set beresp.http.Vary = regsub(beresp.http.Vary, ",? *User-Agent *", "");
        set beresp.http.Vary = regsub(beresp.http.Vary, "^, *", "");
        if (beresp.http.Vary == "") {
            unset beresp.http.Vary;
        }
    }

P.S.: I removed my previous concerns regarding Cookies finding them wrong. default.vcl provided with VarnishCache module makes Varnish to cache content even if Cookie request header is present.

Sincerely yours, Andrew Storozhev

Emulator000 commented 8 years ago

Hi @Guard1an, could you provide more information about this approach? I'm experiencing the same annoying issue without have found a solution yet! Thank you very much!

phoenix-bjoern commented 8 years ago

Make sure you've disabled "Browser Capability Check" for cookies in the Magento configuration (General/Web).

Emulator000 commented 8 years ago

Thank you for you reply @phoenix-bjoern, anyway I can't find this exact option, what I've on the backend is: untitled

Thanks!

phoenix-bjoern commented 8 years ago

It is "Redirect to CMS-page if Cookies are Disabled".

Emulator000 commented 8 years ago

Thanks @phoenix-bjoern, I'm just making some test and I will let you know.

Emulator000 commented 8 years ago

I can confirm that the suggested option by @phoenix-bjoern resolve this issue.