【问题标题】:build category tree for categories and sub categories为类别和子类别构建类别树
【发布时间】:2013-06-27 18:48:17
【问题描述】:

我正在尝试为自定义管理模块中的类别和子类别构建类别树,如果可能的话,覆盖产品编辑选项卡中存在的默认类别树。

以下是我正在工作的代码,它能够构建类别树,但它缺乏复选框功能。任何建议将不胜感激

<?php 
$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>'.
        '<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); ?>

【问题讨论】:

  • 干得好。即使我也试图覆盖默认类别树,但没有运气。为了添加复选框,在表单中创建整个树,并在
  • 中添加具有类别 ID 值的复选框,这将解决您的复选框问题

标签: magento tree


【解决方案1】:
    Please clarify your question as it's bad idea to override core functionality because same function is used by different modules instead you can check functionality of these 

app/design/adminhtml/default/default/template/catalog/product/edit/categories.ph‌​tml app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php 

and then reflect these to your template files

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签