0

问题:

如果您的 magento 企业商店启用了多种货币,并且您正在使用购物车侧边栏快速浏览购物车中的商品:当客户尝试在货币之间切换时,整页缓存将成为恶棍。购物车侧边栏不会根据切换的货币进行更新。

4

1 回答 1

1

我已经在 http://www.eglobeits.com/blog/magento/magento-enterprise-edition-full-page-cache-mutli-currencies-mini-cart-sidebar-issue-when-switching-currencies/上发布了答案,但在下面添加相同的内容以供您快速参考。

修复: 重新定义 Cart Side Place holder 容器并定义一个新的缓存 ID 生成器,而不是使用 fpc 的原始生成器。

请按照以下步骤操作:

1.创建app/code/local/Egits/PageCache/etc/config.xml,内容如下

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

2. 使用以下内容创建 app/code/etc/modules/Egits_PageCache.xml

<?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. 使用以下内容创建 app/code/local/Egits/PageCache/etc/cache.xml

<?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. 使用以下内容创建 app/code/local/Egits/PageCache/Model/Container/Sidebar/Cart.php

<?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. 刷新所有缓存,你就完成了!:).. 很简单... ehhh ??

于 2014-06-30T12:34:00.603 回答