【问题标题】:Magento 1.9.2.0 static block display issues?Magento 1.9.2.0 静态块显示问题?
【发布时间】:2015-10-27 06:07:18
【问题描述】:

Magento 1.9.2.0 静态块显示问题? 我创建了多个静态块 1.9.2.0 并显示了错误的块如何解决此问题。

【问题讨论】:

    标签: magento magento-1.9


    【解决方案1】:

    尝试以下模块可能会有所帮助 1 步。 创建根路径:app\etc\modules Pankaj_Cms.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <Pankaj_Cms>
                <active>true</active>
                <codePool>local</codePool>
                <depends>
                    <Mage_Cms/>
                </depends>
            </Pankaj_Cms>
        </modules>
    </config>
    

    两步 创建根路径:app\code\local\Pankaj\Cms\etc

     <?xml version="1.0"?>
        <config>
                <modules>
                    <Pankaj_Cms>
                        <version>1.0.0</version>
                    </Pankaj_Cms>
                </modules>
                <global>
                    <blocks>
                        <cms>
                            <rewrite>
                                <block>Pankaj_Cms_Block_Block</block>
                                <widget_block>Pankaj_Cms_Block_Widget_Block</widget_block>
                            </rewrite>
                        </cms>
                    </blocks>
                </global>
        </config> 
    

    3步创建根路径:app\code\local\Pankaj\Cms\BlockBlock.php

    <?php
    class Pankaj_Cms_Block_Block extends Mage_Cms_Block_Block {
    
       public function getCacheKeyInfo()
        {
    
          $blockId = $this->getBlockId();
          if ($blockId) {
                $result = array(
                    $blockId,
                    Mage::app()->getStore()->getCode(),
                );
          } else {
               $result = parent::getCacheKeyInfo();
           }
           return $result;
       }
    
    }
    

    4步创建根路径app\code\local\Pankaj\Cms\Block\WidgetBlock.php

    <?php
    class Pankaj_Cms_Block_Widget_Block extends Mage_Cms_Block_Widget_Block
    {
        static protected $_widgetUsageMap = array();
        protected function _beforeToHtml()
        {
            parent::_beforeToHtml();
            $blockId = $this->getData('block_id');
            $blockHash = get_class($this) . $blockId;
    
            if (isset(self::$_widgetUsageMap[$blockHash])) {
                return $this;
            }
            self::$_widgetUsageMap[$blockHash] = true;
    
            if ($blockId) {
                $block = Mage::getModel('cms/block')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->load($blockId);
                if ($block->getIsActive()) {
                    $helper = Mage::helper('cms');
                    $processor = $helper->getBlockTemplateProcessor();
                    $this->setText($processor->filter($block->getContent()));
                    $this->addModelTags($block);
                }
            }
    
            unset(self::$_widgetUsageMap[$blockHash]);
            return $this;
        }
        public function getCacheKeyInfo()
        {
            $result = parent::getCacheKeyInfo();
            $blockId = $this->getBlockId();
            if ($blockId) {
                $result[] = $blockId;
           }
            return $result;
       }
    }
    

    然后清除缓存

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2014-08-19
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多