【问题标题】:Magento: get Categories tree don't show hidden categoriesMagento:获取类别树不显示隐藏类别
【发布时间】:2013-01-22 13:21:14
【问题描述】:

我用这段代码来显示分类树:

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

如何修改它以递归显示隐藏的类别?

非常感谢。

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以设置自定义集合,而不是使用 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多