【发布时间】: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 值的复选框,这将解决您的复选框问题