2013-01-22 50 views
0

我使用此代碼來顯示樹名作:Magento的:得到分類樹不顯示隱藏的類別

$rootcatId= Mage::app()->getStore()->getRootCategoryId(); 
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId); 

function get_categories($categories) { 
    $array= '<ul>'; 
    foreach($categories as $category) { 
     $cat = Mage::getModel('catalog/category')->load($category->getId()); 
     //$count = $cat->getProductCount(); 
     $array .= '<li>'. 
     $category->getId().' <a href="' . Mage::getUrl($cat->getUrlPath()). '">' . 
        $category->getName(); //. "(".$count.")</a>\n"; 
     if($category->hasChildren()) { 
      $children = Mage::getModel('catalog/category')->getCategories($category->getId()); 
      $array .= get_categories($children); 
      } 
     $array .= '</li>'; 
    } 
    return $array . '</ul>'; 
} 
echo get_categories($categories); 

如何修改它recursivly顯示也隱藏類別?

非常感謝。

回答

3

而不是使用getCategories()方法,您可以設置一個自定義集合。這將顯示隱藏的類別,除非另有說明。

例如:

$categories = Mage::getModel('catalog/category') 
->load(Mage::app()->getStore()->getRootCategoryId()) 
->getCollection() 
->addAttributeToSort('position', 'ASC') 
->addFieldToFilter('parent_id',Mage::app()->getStore()->getRootCategoryId()) 
->addFieldToFilter('include_in_menu',1) 
->addAttributeToSelect('name')