magento以编程方式构建类别树

时间:2013-02-02 08:55:01

标签: php magento

我想将类别树添加到选择多个选项控件

我搜索了这个this link

但它给我输出ul li结构如下

enter image description here

但我希望这个树结构选择多个选项

任何人都可以知道链接代码中的更改

1 个答案:

答案 0 :(得分:5)

准备阵列:

public function getCategoriesArray() {

    $categoriesArray = Mage::getModel('catalog/category')
            ->getCollection()
            ->addAttributeToSelect('name')
            ->addAttributeToSort('path', 'asc')
            ->load()
            ->toArray();

    $categories = array();
    foreach ($categoriesArray as $categoryId => $category) {
        if (isset($category['name']) && isset($category['level'])) {
            $categories[] = array(
                'label' => $category['name'],
                'level'  =>$category['level'],
                'value' => $categoryId
            );
        }
    }

    return $categories;
}

以表格形式显示:

    $fieldset->addField('categories', 'multiselect', array(
        'label' => $this->__('Categories'),
        'name' => 'categories',
        'values' => Mage::getModel(...)->getCategoriesArray(),
    ));
相关问题