2013-01-22 4 views
0

나는 가지 범주 트리를 표시하려면이 코드를 사용하여 표시되지 않습니다 얻을 :젠토 : 카테고리 트리 숨겨진 카테고리

$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); 
내가 재귀 또한 숨겨진 카테고리를 보려면 수정할 수있는 방법

?

고마워요.

답변

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')