How to Get current categories of subcategory with product count in magento

 Hello friends today's i'm share How to Get current categories of subcategory with product count in magento

How to Get current categories of subcategory with product count in magento


<?php
$currCat = Mage::registry('current_category');

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

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

        /**
         * getting product collection for a particular category
         * applying status and visibility filter to the product collection
         * i.e. only fetching visible and enabled products
         */
        $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
    }
}



Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post