Sunday, July 8, 2012

How To fetch all categories and subcategories in magento?

$_helper = Mage::helper(‘catalog/category’)
$_categories = $_helper->getStoreCategories()
$currentCategory = Mage::registry(‘current_category’)
if (count($_categories) > 0)
{
foreach($_categories as $_category)
{
echo $_category->getName()
$_category = Mage::getModel(‘catalog/category’)->load($_category->getId())
$_subcategories = $_category->getChildrenCategories()
if (count($_subcategories) > 0)
{
foreach($_subcategories as $_subcategory)
{
echo $_subcategory->getName()
}
}
}
}

No comments:

Post a Comment

Please mention your comments.......