2012-10-02 123 views
0

我編寫了下面的代碼來組合一個自定義的類別菜單。一切正常,但希望類別的順序與管理員面板中定義的順序相同,其中有drap和drop功能。獲取Magento類別與特定類別的管理面板

<?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> 

我試圖用其他方式(based here)可以做到這一點,但我不能。函數返回getChildren()的問題是ID按升序排列的字符串。

一些想法?

回答

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(); 
1

這是我使用在管理員的順序下拉列表框中顯示的類別代碼...關鍵是你可以做一些setOrder(「路徑」,「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); 

像這樣:create array tree from array list

+0

感謝的人。但是,您的代碼只返回頂級類別的管理員的類別。我會盡力改變它,我會在這裏評論任何成功。如果您有任何建議,我會很感激。 –

+0

我已經改變了位置的路徑,它的工作原理。 –