Pages

Wednesday 12 November 2014

Magento subcategory from the parent category

<?php
        $allCats = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*');
        
        foreach($allCats as $category)
        {
            if($category->getParentId() ==  Mage::app()->getStore()->getRootCategoryId() && $category->getIsActive()) // it'll check the root category
            {
                $subcats = $category->getChildren();
                $total_cat_array=explode(',',$subcats);
                foreach($total_cat_array as $subId)
                {
                    $child = Mage::getModel('catalog/category')->load($subId);
                    echo $child->getName();
                }
            }
        }      
  ?>

No comments:

Post a Comment