Forked from wilhelm-murdoch/getChildCategories.php
Last active
August 29, 2015 14:06
-
-
Save sonnygauran/9ecacd87d62be47d9a63 to your computer and use it in GitHub Desktop.
Recursively get Magento categories and children. Parameter to return only ID, and active only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCategories(Mage_Catalog_Model_Category $ParentCategory, $id_only = false, $active = true) { | |
$return = array(); | |
foreach(explode(',', $ParentCategory->getChildren()) as $categoryId) { | |
$Category = Mage::getModel('catalog/category')->load($categoryId); | |
if ($Category->getIsActive()) { | |
if ($id_only) { | |
$return[] = $categoryId; | |
} else { | |
$return[$categoryId] = array( | |
'id' => $Category->getId(), | |
'name' => $Category->getName(), | |
'slug' => $Category->getUrlKey(), | |
'url' => $Category->getUrl(), | |
'active' => $Category->getIsActive(), | |
'children' => array() | |
); | |
} | |
} | |
if($Category->getChildren()) { | |
if ($id_only) { | |
$return = array_merge($return, $this->getCategories($Category, $id_only, $active)); | |
} else { | |
$return[$categoryId]['children'] = $this->getCategories($Category, $id_only, $active); | |
} | |
} | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment