Magento打孔器在缓存时不会加载子块

时间:2016-06-26 22:16:15

标签: php magento caching freepascal

我正在打孔Magentos FPC。我有一个块,根据用户会话中设置的参数加载其他块(横幅)。代码全部工作,如果我添加

动态加载横幅
$layout = Mage::getSingleton('core/layout');
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

到.phtml模板但没有它,块只加载初始(未缓存)页面。第二个和所有进程(缓存)请求无法使用$ this-> getChildHtml或$ this-> getBlockHtml加载块。此外,当我加载核心布局时,这打破了核心消息传递,看起来像是一个黑客。

这是我的app / design / frontend / base / default / layout / amsh_splitpay.xml

<layout>
<default>
    <reference name='root'>
        <block type="splitpay/banner" name="splitpay.banner" template="splitpay/banner.phtml">
            <action method="unsetData"><key>cache_lifetime</key></action>
            <action method="unsetData"><key>cache_tags</key></action>

            <block type="zblocks/block" name="page_top_splitpay_zblock">
                <action method="setPosition">
                    <position>page-top-splitpay</position>
                </action>
            </block>

            <!-- Created custom zblock for page top -->
            <block type="zblocks/block" name="page_top_zblock">
                <action method="setPosition">
                    <position>page-top</position>
                </action>
            </block>
        </block>
    </reference>
</default>
</layout>

在phtml中

<?php

$sp = Mage::getSingleton("customer/session")->getSplitpayOptions();

$block = $this->getBlockHtml('page_top_splitpay_zblock',false);
if(!empty($sp) && !empty($block)){?>
<div class="zblock container hide-for-small-only">
    <div class="row">
        <div class="large-12 columns">
            <?php echo $block; ?>
        </div>
    </div>
</div>
<?php
} else {
    if ($this->getBlockHtml('page_top_zblock',false)): ?>
    <div class="zblock container hide-for-small-only">
        <div class="row">
            <div class="large-12 columns">
                <?php echo $this->getBlockHtml('page_top_zblock',false);
?>
            </div>
        </div>
    </div>
<?php endif;
}
?>
模型/容器/ Banner.php中的

<?php

class Amsh_SplitPay_Model_Container_Banner extends Enterprise_PageCache_Model_Container_Abstract
{

protected function _getCacheId()
{
    $cacheId        = $this->_placeholder->getAttribute('cache_id');
    $cookieCustomer = $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');
    return 'AMSH_SPLITPAY_BANNER_CACHE_' . md5($cacheId) . '_' . $cookieCustomer;
}


protected function _renderBlock()
{
    $block = $this->_getPlaceHolderBlock();
    // only needed if the block uses a template
    $block->setTemplate($this->_placeholder->getAttribute('template'));
    Mage::dispatchEvent('render_block', array(
        'block'       => $block,
        'placeholder' => $this->_placeholder
    ));

    return $block->toHtml();

}

protected function _saveCache($data, $id, $tags = array(), $lifetime = null)
{
    return false;
}
public function applyWithoutApp(&$content)
{
    return false;
}

}

0 个答案:

没有答案