I want to create a custom block to display the subcategories with a certain filter from a category.

So I created a block that extends Mage_Catalog_Block_Layer_View:

class My_Module_Block_Layer extends Mage_Catalog_Block_Layer_View
    protected function _prepareLayout()
        // 2944 is the parent category whose child categories I want to display
        $cat = Mage::getModel('catalog/category')->load(2944);
        return parent::_prepareLayout();

    // I only want the category filter
    public function getFilter()
        return $this->_getCategoryFilter();

The corresponding phtml:

<?php $filter = $this->getFilter(); ?>
<?php echo $filter->getName(); ?>
<?php if ($filter->getItemsCount()): ?>
    <div><?php echo $filter->getHtml() ?></div>
<?php endif; ?>

$filter->getItemsCount() always returns 0. If I use the getFilterS function instead and iterate over all available filters they are returning all available filters with options just fine. The only filter that returns no options is the category filter.

The parent category (2944) is set as anchor (so are its children). Also category filters work just fine on that category page itself (default implementation).

I feel like I am missing something here. Is there more I need to do besides setCurrentCategory?

The Big picture:

I want to create a mega menu that is the same on all pages. This menu should contain a list of categories that apply a brand filter. Of course this should be independent from the default category layer.

Why do I want to do this?

The categories contents fluctuate. At some point categories are empty/disabled and I don't want to manually adjust the mega menu all the time. So I figured I would use the layered navigation to do this for me.


<h2>Brand X</h2>
    <li><a href="pants.html?brand=123">Pants</a></li>
    <li><a href="skirts.html?brand=123">Skirts</a></li>
    <li><a href="blouses.html?brand=123">Blouses</a></li>
    <li><a href="shoes.html?brand=123">Shoes</a></li>

<h2>Brand Y</h2>
    <li><a href="pants.html?brand=124">Pants</a></li>
    <li><a href="skirts.html?brand=124">Skirts</a></li>
    <li><a href="blouses.html?brand=124">Blouses</a></li>

This is a desired result. For brand X all subcategories are available while for brand Y the shoes category is not since it does not contain any products of this brand.

Once there are shoes of brand Y available that category should show up as well.

Your Answer

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

Browse other questions tagged or ask your own question.