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);
}

本文介绍如何在Magento中使用Mage_Catalog_Model_Category类获取子类别,包括直接获取子类别ID列表和获取子类别实例数组的方法。
5896

被折叠的 条评论
为什么被折叠?



