【问题标题】:magento category searchmagento 类别搜索
【发布时间】:2012-09-17 07:17:51
【问题描述】:

我在类别树的导航下有两个主要的孩子,如下图所示

我想列出 RegionActivity 的类别和子类别,为此我尝试了两种不同的功能

$collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('name')->load();
    foreach ($collection as $cat) {
        echo $cat->getName();
    }  

这将返回 Region 和 Actities 以及另一个函数的所有子节点

$children = Mage::getModel('catalog/category')->getCategories(10);
foreach ($children as $category) {
  echo $category->getName();
} 

Reference link

这仅返回子类别

我想列出所有类别,子类别和子子类别等等...对于区域

提前致谢

【问题讨论】:

    标签: magento magento-1.6


    【解决方案1】:

    试试这个:

        $rootcatId= 10;
        $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>'.
                '<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); 
    

    【讨论】:

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