Blogroll

Sunday, April 8, 2012

List category and subcategory in magento

I found below code to list category and subcategory . I can put it everywhere in your website.

$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
function  get_categories($categories) {
    $array= '
    '; foreach($categories as $category) { $cat = Mage::getModel('catalog/category')->load($category->getId()); $count = $cat->getProductCount(); $array .= '
  • '. '' . $category->getName() . "(".$count.")\n"; if($category->hasChildren()) { $children = Mage::getModel('catalog/category')->getCategories($category->getId()); $array .= get_categories($children); } $array .= '
  • '; } return $array . '
'; } echo get_categories($categories); ?>
Olá! Se você ainda não assinou, assine nosso RSS feed e receba nossas atualizações por email, ou siga nos no Twitter.
Nome: Email:

0 comments:

Post a Comment