Magento custom cache issue on product view page

时间:2016-10-19 13:40:01

标签: magento caching product catalog

We added the custom cache for product view page.

We rewrite the view.php file and write below code :

<?php
/**
 * Rewriting Product View block
 */
class XXX_YYY_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{

    protected function _construct()
    {
        $this->addData(array(
         //'cache_key'   => 
            //'cache_lifetime'  => 
            'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getProduct()->getId()),
        ));
    }

    public function getCacheKey()
    {
        if (!$this->hasData('cache_key')) {
         //$cacheKey = LAYOUTNAME_STORE+ID_PRODUCT+ID
         $cacheKey = $this->getNameInLayout().'_STORE'.Mage::app()->getStore()->getId().'_PRODUCT'.$this->getProduct()->getId();
         //.'_'.Mage::getDesign()->getPackageName().'_'.Mage::getDesign()->getTheme('template'). //_PACKAGE_THEME ?
         $this->setCacheKey($cacheKey);
        }
        return $this->getData('cache_key');
    }

    public function getCacheLifetime()
    {   //to prevent sub-blocks caching
       if($this->getNameInLayout()!='product.info') return null;
       //return false; //false creates default lifetime (7200)
       return 9999999999;
    }

}
?>

After the rewrite code added the add to cart functionality and global messages not working in product view page.

Help to fix this issue.

Thanks

0 个答案:

没有答案