0

我编写了下面的代码来组合一个自定义的类别菜单。一切正常,但希望类别的顺序与管理员面板中定义的顺序相同,在那里有拖放功能。

<?php
    $subCats = Mage::getModel('catalog/category')->load(76)->getChildren();
    $dispositosCatIds = explode(',',$subCats);
?>
<ul class="menu">
<?php $controleNum = 0; ?>
<?php foreach($dispositosCatIds as $dispositoCatId): ?>
<?php $aparelhoCat = Mage::getModel('catalog/category')->load($dispositoCatId); ?>
<?php if($aparelhoCat->getIsActive()): ?>
    <li class="<?php print $controleNum ? '' : 'submenu first'; ?>"><a class="drop" href="<?php echo $aparelhoCat->getUrl(); ?>"> <span><?php echo $aparelhoCat->getName(); ?></span></a> <!--Begin 6 column Item  -->
    <div class="dropdown_6columns">
    <div class="inner"><span class="title"><?php echo $aparelhoCat->getName(); ?></span>
    <div class="col_2">
    <div class="col_2 firstcolumn"><img src="<?php echo $aparelhoCat->getImageUrl(); ?>" alt="<?php echo $aparelhoCat->getName(); ?>" /></div>
    </div>
    <div class="col_4" style="margin-bottom: 20px;">
        <?php echo $aparelhoCat->getDescription(); ?>
    </div>
    <div class="col_2 categorias-super"><span class="title_col">Produtos para <?php echo $aparelhoCat->getName(); ?></span> 
    <?php $subSubCats = $aparelhoCat->getChildrenCategories();?>

    <?php if (count($subSubCats) > 0): ?>
        <?php //$controleNumLI = 0; ?>
        <ul style="list-style: none; float: none !important;">
        <?php foreach($subSubCats as $_subcategory): //Rodando entre as categorias de Um dispositivo ?>
            <?php if($_subcategory->getIsActive()): ?>
                <li class="level1 <?php //print $controleNumLI ? '' : 'first'; ?>"> <a href="<?php echo $_subcategory->getUrl(); ?>"><?php echo $_subcategory->getName(); ?></a></li>
                <?php //$controleNumLI += 1; ?>
            <?php endif; ?>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    </div>
    </div>
    </div>
    </li>
    <?php $controleNum += 1; ?>
<?php endif; ?>    
<?php endforeach; ?>
</ul>

我尝试使用其他模式(基于此处)可以做到这一点,但我做不到。该函数返回的问题getChildren()是一个 ID 升序排列的字符串。

一些想法?

4

2 回答 2

1

这是我用来按管理员顺序在下拉框中显示类别的代码...关键是 setOrder('path','ASC')

    $categories = array();

    $_categories = Mage::getModel('catalog/category')->getCollection()
                            ->addAttributeToFilter('is_active',array('eq'=>true))
                            ->addAttributeToSelect('level')
                            ->setOrder('path','ASC')
                            ->addAttributeToSelect('name')->load();




    foreach($_categories as $cat){
        $level = $cat->getLevel() - 1;
        $pad = str_repeat("----", ($level > 0) ? $level : 0);

        $categories[] = array('value' => $cat->getEntityId(), 'label' => $pad . ' ' . $cat->getName());
    }

    print_r($categories);

你可以这样做:从数组列表创建数组树

于 2012-10-02T21:17:36.553 回答
1

我得到了它:

$dispositovosCategoryId = 76;
$dispositovosCategoryIds = Mage::getModel('catalog/category')->getCollection()
    ->addFieldToFilter('parent_id', array('eq'=>$dispositovosCategoryId))
    ->addAttributeToFilter('is_active',array('eq'=>true))
    ->addAttributeToSelect('level')
    ->setOrder('position','ASC')
    ->addAttributeToSelect('name','url','image')
    ->load();
于 2012-10-05T14:36:09.263 回答