Magento:在下拉列表中显示管理员产品类别

时间:2016-04-27 03:12:27

标签: magento html-select magento-1.9 objective-c-category

我想将类别选择显示为下拉菜单而不是使用+符号进行渲染 magento / admin / product /新产品类别选择 见下图供参考。

enter image description here

1 个答案:

答案 0 :(得分:1)

这是代码,您可以在模块的块或帮助器下创建波纹管功能。

    function getCategoriesTreeView() {
    // Get category collection
    $categories = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToSort('path', 'asc')
    ->addFieldToFilter('is_active', array('eq'=>'1'))
    ->load()
    ->toArray();

   // Arrange categories in required array
   $categoryList = array();
   foreach ($categories as $catId => $category) {
    if (isset($category['name'])) {
        $categoryList[] = array(
            'label' => $category['name'],
            'level'  =>$category['level'],
            'value' => $catId
        );
    }
}
return $categoryList;
 }

现在是设计时间,下面是代码,它会给你下拉类别。

<select id="categorylist" name="categorylist">
<option value="">Select Category</option>
<?php
$categoriesTreeView = getCategoriesTreeView();

foreach($categoriesTreeView as $value)
{
    $catName    = $value['label'];
    $catId      = $value['value'];
    $catLevel    = $value['level'];

    $space = '&nbsp;';
    for($i=1; $i<$catLevel; $i++){
        $space = $space."&nbsp;";
    }
    $catName = $space.$catName;

    ?>
 <option value="<?php echo $catIdIs; ?>"><?php echo $catName ?></option>
 <?php
}
?>
</select>