`
kirenenko04
  • 浏览: 152278 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

retrieve all children categories given a category id

 
阅读更多

I think the class Mage_Catalog_Model_Category already includes the function you are searching. It is called getChildren:

public function retrieveAllChilds($id = null, $childs = null) {
    $category = Mage::getModel('catalog/category')->load($id);
    return $category->getChildren();
}

 The function getChildren returns children IDs comma-separated, getChildrenCategoriesreturns an array of Mage_Catalog_Model_Category instances.

If you want to get the children categories recursively, you can use:

public function retrieveAllChilds($id = null, $childs = null) {
    $category = Mage::getModel('catalog/category')->load($id);
    return $category->getResource()->getChildren($category, true);
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics