1

I've managed to display the sub categories in my own block.

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
      ->addAttributeToSelect(array('name', 'image'))
    ->addAttributeToFilter('is_active', 1)
    ->addAttributeToSort('position', 'asc')
    ->addIdFilter($category->getChildren());
?>
<ul class="products-grid grid-type-1 column4 row">
<?php foreach ($categories as $category): ?>
   <li class="item">
        <div class="product-image-wrapper">
             <a title="<?php echo $category->getName() ?>" href="<?php echo $category->getUrl() ?>">
                <img width="300" height="300" src="<?php echo $category->getImageUrl() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
            </a>
        </div>
        <h2 class="product-name">
            <a title="<?php echo $category->getName() ?>" href="<?php echo $category->getUrl() ?>">
                <?php echo $category->getName() ?>
            </a>
        </h2>
    </li>
<?php endforeach; ?>

Call this block from a CMS static block and when necessary set this in the design settings in the category.

My problem is that while I was developing I had the cached turned off it was working fine, once I enabled the cache it broke, to get around this issue I've disabled the 'Blocks HTML output' in the cache management, this is only a temporary measure but this module will need to enable to help page speed

The version of Magento is 1.9.2.2. Is there any fix to get around this issue.

UPDATE

I've created a block and overridden the getCacheKeyInfo method

public function getCacheKeyInfo()
{
    return array(
                    'SUBCATEGORY',
                    $this->getNameInLayout(),
                    Mage::app()->getStore()-getId(),
                    (int)Mage::app()->getStore()->isCurrentlySecure(),
                    Mage::getDesign()->getPackageName(),
                    Mage::getDesign()->getTheme('template'),
                    'CATEGORY-'.Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId()
                 );
}
2

You don't want to disable the caching for the block, but instead implement your own block type and make sure, that the cache key contains all informations about the context - I think in your case this is only parent category?

What you want is to implement getCacheKeyInfo() on your own block class to solve this.

  • Better than mine, I am deleting my answer – Raul Sanchez Jan 29 '16 at 15:35
  • I don't have separate code for this, I just have the .phtml file which contains the code above. Can I add the code in here? – user9252 Feb 1 '16 at 11:30
  • No, but you can do it via Layout-xml as in the first example here fbrnc.net/blog/2015/06/cache-and-layout-xml-tricks – Fabian Blechschmidt Feb 1 '16 at 14:25
  • I've created a block which extends from Mage_Core_Block_Abstract and overridden the getCacheKeyInfo method but it is not working – user9252 Feb 2 '16 at 21:22

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.