开发者

Magento - different record on category and sub category page

开发者 https://www.devze.com 2023-03-09 11:05 出处:网络
I have 2 category level (top level & sub category). On the top category page i need to show all the sub category with few of the sub category products for each sub categories. Also need to show so

I have 2 category level (top level & sub category). On the top category page i need to show all the sub category with few of the sub category products for each sub categories. Also need to show some other details on the top level category page.

On the sub category page,开发者_C百科 need to show the sub category products.

As we have one template page for category and sub category product page.

How this can be handled.


Maybe this link is helpfull for displaying subcategories. http://fishpig.co.uk/display-categories-and-subcategories-in-magento/

And for the Products you can see if the use as anchor works for you or you try http://oggettoweb.com/blog/news/magento-extension-product-blocks/ or you modify your template to pull some products with certain attributes


$currCat = Mage::registry('current_category');

/**
 * get sub categories of current category
 */
$collection = Mage::getModel('catalog/category')
                   ->getCategories($currCat->getEntityId());

/** 
 * only showing active sub categories
 */
foreach($collection as $cat) {
    if($cat->getIsActive()) {
        $category = Mage::getModel('catalog/category')
                         ->load($cat->getEntityId());

        $prodCollection = Mage::getResourceModel('catalog/product_collection')
                               ->addCategoryFilter($category);

        Mage::getSingleton('catalog/product_status')
             ->addVisibleFilterToCollection($prodCollection);

        Mage::getSingleton('catalog/product_visibility')
             ->addVisibleInCatalogFilterToCollection($prodCollection);

        ?>

        <a href="<?php echo $category->getUrl() ?>">
           <?php echo $category->getName() ?>
        </a> (<?php echo $prodCollection->count() ?>)<br/>

        <?php
    }
}

Source: Get Sub Categories & Product Count

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号