Magento Enterprise Full Page Cache(FPC) Cart Sidebar issue when Switching between Multiple currencies

1.3k Views Asked by At

The Issue:

If your magento enterprise store has multiple currencies enabled and you are using Cart Sidebar to give a quick overview of items in the cart: Full Page Cache will be a villain when the customer try to switch between currencies. The Cart Sidebar won't get updated based on the currency switched.

1

There are 1 best solutions below

0
On BEST ANSWER

I have published the answer at http://www.eglobeits.com/blog/magento/magento-enterprise-edition-full-page-cache-mutli-currencies-mini-cart-sidebar-issue-when-switching-currencies/, but Adding the same below for your quick reference.

The Fix: Redefine the Cart Side Place holder container and define a new cache Id generator rather than Using fpc's original one.

Follow below Steps:

1. Create app/code/local/Egits/PageCache/etc/config.xml with following content

   <?xml version="1.0"?>
   <config>
       <modules>
           <Egits_PageCache>
               <version>0.0.1</version>
           </Egits_PageCache>
       </modules>
    </config>

2. Create app/code/etc/modules/Egits_PageCache.xml wih following content

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Egits_PageCache>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Enterprise_PageCache />
            </depends>
        </Egits_PageCache>
    </modules>
</config>

3. Create app/code/local/Egits/PageCache/etc/cache.xml wih following content

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <placeholders>
        <cart_sidebar>
            <block>checkout/cart_sidebar</block>
            <placeholder>CART_SIDEBAR</placeholder>
            <container>Egits_PageCache_Model_Container_Sidebar_Cart</container>
            <cache_lifetime>86400</cache_lifetime>
        </cart_sidebar>
    </placeholders>
</config>

4. Create app/code/local/Egits/PageCache/Model/Container/Sidebar/Cart.php with following content

<?php

class Egits_PageCache_Model_Container_Sidebar_Cart extends Enterprise_PageCache_Model_Container_Sidebar_Cart
{
    const CURRENCY_COOKIE = 'currency';

    /**
      * Get cache id for the block
      * @return string
      */
    protected function _getCacheId()
    {
        $cookieCart = Enterprise_PageCache_Model_Cookie::COOKIE_CART;
        $cookieCustomer = Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER;
        $curreny = array_key_exists(self::CURRENCY_COOKIE, $_COOKIE) ? $_COOKIE[self::CURRENCY_COOKIE] : '';
        return md5(
            Enterprise_PageCache_Model_Container_Advanced_Quote::CACHE_TAG_PREFIX
            . (array_key_exists($cookieCart, $_COOKIE) ? $_COOKIE[$cookieCart] : '')
            . (array_key_exists($cookieCustomer, $_COOKIE) ? $_COOKIE[$cookieCustomer] : '')
            . $curreny
        );
    }

}

4. Flush All your caches and you are done! :).. Pretty Simple... ehhh??