【发布时间】:2013-03-29 21:22:26
【问题描述】:
我的 magento 主页内容显示不止一次。我希望它们每页只出现一次。
我尝试将此代码放入 \app\code\core\Mage\Catalog\Block\Product\List.php 文件作为解决方案:
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => 900,
'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG),
'cache_key' => $this->getCacheKey()
));
}
public function getCacheKey()
{
return $this->getRequest()->getRequestUri().$this->getCacheCurrencyCode();
}
//retreive current currency code
public function getCacheCurrencyCode()
{
return Mage::app()->getStore()->getCurrentCurrencyCode();
}
在此编辑之后,每当我访问我的主页时,我都会看到一些商品在畅销品类别中重复了三遍,如下面的屏幕截图所示:
出现当前错误的意外主页: http://ikelk.lt/i/131171/o_afb38c9691.JPG
理想情况下的外观(预期行为): http://ikelk.lt/i/131172/o_568243b784.JPG
感谢您的帮助。
【问题讨论】:
-
将产品详情添加到缓存时,您还应该在缓存标签中添加产品 ID/列表类型字符串。
-
问题与布局有关。您需要检查 CMS >Pages > home 的内容/布局以及所有 layouts.xml 文件。在某个地方你两次指定了同一个块。
-
@SatishMantri 你有没有想过这样的代码:array(Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getProduct()->getId()),如果是的话重复相同的问题内容。 @Serijo 我检查了 CMS>Pages>home,这里有不同的代码行。
-
我的主页代码:{{block type="catalog/product_list_random" category_id="175" template="catalog/product/geriausipasiulymai.phtml" column_count="2" num_products="6"}} {{block type="catalog/product_list_random" category_id="176" template="catalog/product/naujienos.phtml" column_count="2" num_products="6"}} {{block type="catalog/product_list_random" category_id= "178" template="catalog/product/populiariausipasiulymai.phtml" column_count="2" num_products="4"}}
-
您需要一个类别 ID 标签作为缓存标签。
标签: html magento caching block