1

I have followed the tutorial found here to list their sub-categories on my category pages.

However, after the first category page visit it displays the sub-categroies of this category page for all subsequent category pages.

Investigating the issue, I found it to be caused by the cache: Blocks HTML output. And, researching the issue I see in previous version(s) magento doesn't cache dynamic static blocks correctly.

I am using the latest version yet the issue still persists, I have currently disabled the aforementioned cache: Bad practice I know. But, it is the only way to make it work.

I am at a loose end and was wondering if anyone could possibly provide further clarification on the matter or how I can either disable this cache for my block only or correct the issue

Update:

Here is my code if it helps:

The phtml file:

    <div class="category-products2">
<ul class="products-grid subGrid">
<?php
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
$categorycount = 0;
foreach ($_categories as $_category):
if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
if ($categorycount == 0){
$class = "first";
}
elseif ($categorycount == 3){
$class = "last";
}
else{
$class = "";
}
?>
<li class="item <?=$class?> dropshadowclass">
<a class="product-image" href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><img src="<?php echo $_category->getImageUrl() ?>" width="100%" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" /></a>

<h2 class="subImageCat"><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h2>
</li>
<?php
endif;
if($categorycount == 3){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid subGrid\">";
}
else{
$categorycount++;
}
endforeach;
endif;
?>
</ul>
</div>

Updated getCurrentChildCategories() function:

    public function getCurrentChildCategories()
   {
        $layer = Mage::getSingleton('catalog/layer');
        $category   = $layer->getCurrentCategory();
        /* @var $category Mage_Catalog_Model_Category */
        $collection = Mage::getModel('catalog/category')->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        $collection->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('is_anchor')
            ->addAttributeToSelect('image') 
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren())
            ->setOrder('position', 'ASC')
            ->joinUrlRewrite()
            ->load();

        $productCollection = Mage::getResourceModel('catalog/product_collection');
        $layer->prepareProductCollection($productCollection);
        $productCollection->addCountToCategories($collection);
        return $collection;
    } 

Attempts so far to disable cache for this static block:

1) In local.xml under default layout handle:

    <reference name="categorysub">
     <action method="unsetData"><key>cache_lifetime</key></action>
     <action method="unsetData"><key>cache_tags</key></action>
    </reference>

and,

     <reference name="categorysub"><action method="unsCacheLifetime"></action></reference>

2) On the block declaration:

    cache_lifetime="null"
    cache_lifetime=null
    cache_lifetime=0

Update 2:

Trying out Rimeshs' answer below fixes the issue, but it hasn't been active recently and would like to confirm that it is still safe for production usage?

0
0

This problem was introduced in 1.9.2.X release to improve performance.

Use below link to get the fix.

https://github.com/progammer-rkt/Rkt_SbCache

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.