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

Problem when I add a product in cart first time #42

Open thiagorock22 opened 8 years ago

thiagorock22 commented 8 years ago

I noticed when I visit my ecommerce first time the cookie key "frontend" is not created, only after visit area that doesn't have a cache. The problem is when I use ajax to add a cart and there is no a cookie key "frontend", the cart remains empty. How I resolve it?

phizab commented 8 years ago

We noticed the same problem and solved it by changing the file app/design/frontend/base/default/template/varnishcache/cookie/formkey.phtml in line 33:

From: if (document.cookie.length && (document.cookie.indexOf('<?php echo $_cookieName; ?>=') == -1)) {

To: if (document.cookie.indexOf('<?php echo $_cookieName; ?>=') == -1) {

Does anybody know why there is the cookie length check?

dleone81 commented 8 years ago

I've tried your fix and works on Magento single store! I've a multi-store Magento installation and I following your tip and added some additional steps:

  1. I've not hardcoded varnishcache/cookie/formkey.phtml but I've created this into my custom template folders -> app/design/frontend/default/mycustomtemplate/template/varnishcache/cookie/formkey.phtml
  2. Added in System > Configuration > General > Web > Cookie Session, foreach domain I've add the specific url as www.mydomain.com and b2b.mydomain.com
  3. Flush Magento cache
  4. Clear all cache
  5. Clear Varnish cache
  6. Restart Varnish (optional but recommended)

Thank you

Magento 1.8.1 Varnish 3.0 NginX + PHP-FPM

xinhus commented 8 years ago

I've solved it with the setting "Use SID on Frontend" to "yes" System > Configuration > General > Web > Session Validation Settings

I don't know if has logic, but worked fine

Emulator000 commented 8 years ago

Same issue here, if I open the site the first time in Incognito mode I can see a different form_key generated and the PAGECACHE_FORMKEY is different also after refreshing the page etc. Can't add any Product to the cart and the site is unusable.

I'm missing something? How I can make it work correctly every time someone visit the site?

dleone81 commented 8 years ago

solved using Lesti-FPC! Varnish make me crazy ... it was very very fast on loading but so hard to configure no-cache elements as megamenu ...