正确地通过Magento全页缓存打孔

时间:2014-08-28 15:47:29

标签: php xml magento caching

我一直在把头发拉出来试图在产品页面上打出一个打孔的价格块。我已经查看了很多来源,包括一些来自stackoverflow的好人,但是我遇到了一个致命的错误,所以有些不对劲。以下是我使用的一些资料来源:

http://invisiblezero.net/magento-ee-punch-hole-in-full-page-cache/

http://www.kingletas.com/2012/09/how-does-magento-full-page-cache-works.html

Magento full page cache

Trying get dynamic content hole-punched through Magento's Full Page Cache

How to implement magento cache hole punching for shopping cart block

正如你所看到的,我已经全身心投入了,而且除了这个之外我还阅读了更多内容但是其中一些冲突很少,我认为这就是我的问题,现在让我为你发布一些代码

cache.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <placeholders>
         <SpecialPrice>
            <block>catalog/product_price</block>
            <name>product.pricing</name>
            <placeholder>CATALOG_PRODUCT_PRICE</placeholder>
            <container>MyStore_SpecialPrice_Model_Container_Cache</container>
            <cache_lifetime>8640</cache_lifetime>
        </SpecialPrice>
    </placeholders>
</config>

cache.php

<?php
class MyStore_SpecialPrice_Model_Container_Cache extends Enterprise_PageCache_Model_Container_Abstract
{
/**
* Get customer identifier from cookies
*
* @return string
*/
protected function _getIdentifier()
{
return $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');
}

/**
* Get cache identifier
*
* @return string
*/
protected function _getCacheId()
{
return 'CATALOG_PRODUCT_PRICE' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
}

/**
* Render block content
*
* @return string
*/
protected function _renderBlock()
{
$blockClass = $this->_placeholder->getAttribute('block');
$template = $this->_placeholder->getAttribute('template');

$block = new $blockClass;
$block->setTemplate($template);
return $block->toHtml();
}
}

congig.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MyStore_SpecialPrice>
            <version>0.1.0</version>
        </MyStore_SpecialPrice>
    </modules>
    <frontend>
        <events>
            <catalog_product_get_final_price>
                <observers>
                    <MyStore_SpecialPrice_Model_Observer>
                        <class>MyStore_SpecialPrice_Model_Observer</class>
                        <method>setSpecialPrice</method>
                    </MyStore_SpecialPrice_Model_Observer>
                </observers>
            </catalog_product_get_final_price>
        </events>
    </frontend>
    <admin>
        <routers>
            <SpecialPrice>
                <use>admin</use>
                <args>
                    <module>MyStore_SpecialPrice</module>
                    <frontName>SpecialPrice</frontName>
                </args>
            </SpecialPrice>
        </routers>
    </admin>
    <global>
        <models>
            <SpecialPrice>
                <class>MyStore_SpecialPrice_Model</class>
            </SpecialPrice>
        </models>
    </global>
</config>
来自local.xml的

片段

<reference name="right">
            <block type="catalog/product_price" name="product.pricing" template="catalog/product/product-price-block.phtml" before="-" >

如果有任何事情发生在你身上,请告诉我。

0 个答案:

没有答案