2015-02-24 75 views
0

目前的所有的孩子我有這個獲得類別的孩子:Magento的:獲取一個特定的類別

$category = Mage::getModel('catalog/category')->load($categoryId); 
$childrenIds = $category->getResource()->getChildren($category, true); 

然而,將只得到活潑的孩子。有沒有辦法讓特定類別的所有孩子,包括殘疾類別?

+0

你必須編寫SQL直接對數據庫的能力嗎? – 2015-02-24 04:02:02

回答

0

試試下面

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

代碼試試這個:

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