문제

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.

도움이 되었습니까?

해결책

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 />';
}

다른 팁

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; ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top