Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Product Count Per Category in Magento


<ul>              
  <?php $id = 42;?>
  <?php $cat = Mage::getModel('catalog/category')->load($id);?>
  <?php $subcats = $cat->getChildren();?>
  <?php foreach(explode(',',$subcats) as $subCatid):?>
  <?php $_category = Mage::getModel('catalog/category')->load($subCatid);?>
  <?php if($_category->getIsActive()):?>  
  <?php $productCount = Mage::getModel('catalog/category')->load($_category->getId())->getProductCount();?>

 <li><a href="<?php echo $_category->getURL();?>"><span><?php echo $_category->getName();?><?php echo '('.$productCount.')'?></span></a></li>

<?php endif;?>
<?php endforeach;?>
</ul>

Please support us, Like us on Facebook.

0 comments:

Post a Comment

 

Copyright @ 2017 HKBlog.