Question

I had a project where there was no pattern and I applied all changes of categories layout in Admin area (Catalog->Manage Categories->Custom Design tab). Now I need to have the following:
Parent category will have a grid of all subcategories with their thumbnails and titles.

Subcategories will look pretty much as default ones - Name, description and product list/grid

So I would like to do this and wonder what is the right way.

Was it helpful?

Solution

In your catalog/category/view.phtml you can check the category level using this:

$this->getCurrentCategory()->getLevel()

If you want to decide this in the backend you could make a whole seperate template that displays all the subcategories and add the following to your custom layout updates:

<reference name="category.products">
    <action method="setTemplate"><template>catalog/category/list.phtml</template></action>
</reference>

To read out all the subcategories you can do this:

$children = explode(',', $this->getCurrentCategory()->getChildren());
$collection = Mage::getModel('catalog/category')->getCollection()
        ->addAttributeToSelect('name')
        ->addAttributeToFilter('entity_id', array(
            'in' => $children
        ))->load();

foreach ($collection as $category) {
    echo $category->getName() . '<br />';
}

OTHER TIPS

You should be able to put an if block at the top of the catagory view template.

Something like:

<?php if ($this->IsTopCategory()) : ?>

// Insert subcategory grid logic here

<?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top