Answers:
由于这是EE,所以我可以利用Magento的支持,但我也自己解决了一些问题,以帮助解决问题并尽快获得解决方案。代码更改由Magento提供,因此可以将它们应用到实际的app / code / core文件中,尽管您始终可以在/ app / code / local中复制文件并在其中应用更改。
问题在于,1.14.2中添加的块缓存方法没有生成唯一的缓存键,因此,当我在类别控制器空间中使用了多个块时,生成的缓存键最终仅对第一个页面命中是唯一的,导致所有这些页面显示重复的内容。
解决方法是添加以下内容(以diff文件格式显示,以显示添加内容周围的上下文-只需在需要添加+的行中添加):
在第72行的app / code / core / Mage / Cms / Block / Block.php中:
}
return $html;
}
+
+ /**
+ * Retrieve values of properties that unambiguously identify unique content
+ *
+ * @return array
+ */
+ public function getCacheKeyInfo()
+ {
+ $blockId = $this->getBlockId();
+ if ($blockId) {
+ $result = array(
+ $blockId,
+ Mage::app()->getStore()->getCode(),
+ );
+ } else {
+ $result = parent::getCacheKeyInfo();
+ }
+ return $result;
+ }
}
在第82行的app / code / core / Mage / Cms / Block / Widget / Block.php中:
$helper = Mage::helper('cms');
$processor = $helper->getBlockTemplateProcessor();
$this->setText($processor->filter($block->getContent()));
+ $this->addModelTags($block);
}
}
unset(self::$_widgetUsageMap[$blockHash]);
return $this;
}
+
+ /**
+ * Retrieve values of properties that unambiguously identify unique content
+ *
+ * @return array
+ */
+ public function getCacheKeyInfo()
+ {
+ $result = parent::getCacheKeyInfo();
+ $blockId = $this->getBlockId();
+ if ($blockId) {
+ $result[] = $blockId;
+ }
+ return $result;
+ }
}
我想我不会是唯一看到此问题的人,并且如果它在CE 1.9.2中出现,希望对某些人有帮助。
我认为正确的方法是我们需要创建Custom模块,因为大家都知道Magento Boogieman会帮到您!如果改变核心:)
您将需要以下文件: app/etc/modules/Bhupendra_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Bhupendra_Cms>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Cms/>
</depends>
</Bhupendra_Cms>
</modules>
</config>
app/code/local/Bhupendra/Cms/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Bhupendra_Cms>
<version>1.0.0</version>
</Bhupendra_Cms>
</modules>
<global>
<blocks>
<cms>
<rewrite>
<block>Bhupendra_Cms_Block_Block</block>
<widget_block>Bhupendra_Cms_Block_Widget_Block</widget_block>
</rewrite>
</cms>
</blocks>
</global>
</config>
app/code/local/Bhupendra/Cms/Block/Block.php
<?php
class Bhupendra_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;
}
}
app/code/local/Bhupendra/Cms/Block/Widget/Block.php
class Bhupendra_Cms_Block_Widget_Block extends Mage_Cms_Block_Widget_Block
{
/**
* Storage for used widgets
*
* @var array
*/
static protected $_widgetUsageMap = array();
/**
* Prepare block text and determine whether block output enabled or not
* Prevent blocks recursion if needed
*
* @return Mage_Cms_Block_Widget_Block
*/
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()) {
/* @var $helper Mage_Cms_Helper_Data */
$helper = Mage::helper('cms');
$processor = $helper->getBlockTemplateProcessor();
$this->setText($processor->filter($block->getContent()));
$this->addModelTags($block);
}
}
unset(self::$_widgetUsageMap[$blockHash]);
return $this;
}
/**
* Retrieve values of properties that unambiguously identify unique content
*
* @return array
*/
public function getCacheKeyInfo()
{
$result = parent::getCacheKeyInfo();
$blockId = $this->getBlockId();
if ($blockId) {
$result[] = $blockId;
}
return $result;
}
}
有关更多信息,您可以访问以下博客,也可以从其下载 https://www.milople.com/blogs/ecommerce/solved-magento-static-block-display-issue.html
也可以通过以下扩展名来修复此错误(无需编辑核心文件或重写块):
https://github.com/progammer-rkt/Rkt_SbCache
并且它还包含@AdvancedLogic提到的行,以避免不安全的内容警告:
(int)Mage::app()->getStore()->isCurrentlySecure()