Magento:获取特定类别的所有子级

Magento:获取特定类别的所有子级,magento,magento-1.9,Magento,Magento 1.9,目前,我有以下功能来获取某个类别的子级: $category = Mage::getModel('catalog/category')->load($categoryId); $childrenIds = $category->getResource()->getChildren($category, true); 然而,它只会得到活跃的子对象。是否有办法获取特定类别的所有子级,包括禁用类别?请尝试下面的代码 $categoryId = 8; // your parent c

目前,我有以下功能来获取某个类别的子级:

$category = Mage::getModel('catalog/category')->load($categoryId);
$childrenIds = $category->getResource()->getChildren($category, true);
然而,它只会得到活跃的子对象。是否有办法获取特定类别的所有子级,包括禁用类别?

请尝试下面的代码

$categoryId = 8; // your parent category id    
$category = Mage::getModel('catalog/category')->load($categoryId);
$childrenIdsWithInactive = $category->getChildrenCategoriesWithInactive()->getAllIds();
试试这个:

<?php function getTreeCategories($parentId, $isChild){
        $allCats = Mage::getModel('catalog/category')->getCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('parent_id',array('eq' => $parentId));
        foreach ($allCats as $category){
            $html .= $category->getId().",";
            $subcats = $category->getChildren();
            if($subcats != ''){
                $html .= getTreeCategories($category->getId(), true);
            }
        }
        return $html;
    }
    $catlistHtml = getTreeCategories("category_id", false); ?>

您是否能够针对数据库编写直接SQL?