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()
                 );
}
user9252
  • 329
  • 1
  • 3
  • 11

1 Answers1

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.

Fabian Blechschmidt
  • 35,388
  • 8
  • 75
  • 182