3

我使用 Magento 1.7.2,并显示当前类别的子类别和子子类别列表。我的问题是子子类别的顺序与管理后端树结构中的顺序不同。看起来他们是通过他们的 id 排序的,从小到大的 id 号。我需要它们在管理后端中按顺序显示。这是我当前的代码:

<?php 
$currCat = Mage::registry('current_category');
$parentname = $currCat->getName();
$collection = Mage::getModel('catalog/category')->getCategories($currCat->getEntityId());
$subcats = $currCat->getChildren();

$_helper = $this->helper('catalog/output');
echo '<h2 class="titleCat"><strong>'.$parentname.'</strong></h2>';
?>

<?php 
$currCat = Mage::registry('current_category');
$parentname = $currCat->getName();
$collection = Mage::getModel('catalog/category')->getCategories($currCat->getEntityId());
$subcats = $currCat->getChildren();

$_helper = $this->helper('catalog/output');
echo '<h2 class="titleCat"><strong>'.$parentname.'</strong></h2>';
?>

<!-- We list sub sub categories -->
<div class="colLeftNav">
<ul class="colLeftSubCats">
<?php
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive()) {
$sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
$sub_subcats = $sub_cat->getChildren();
echo '<div class="subMainCat"><a href="'.$_category->getURL().'" title="Show products "'.$_category->getName().'" category">'.$_category->getName().'</a></div>';
foreach(explode(',',$sub_subcats) as $sub_subCatid)
{
$_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
if($_sub_category->getIsActive()) {
echo '<li class="subCat"><a href="'.$_sub_category->getURL().'" title="show products "'.$_sub_category->getName().'" category">'.$_sub_category->getName().'</a></li>';
}
}
}
}
?>
</ul>
</div>

我几乎被困在这里,不知道如何解决这个问题。任何帮助将非常感激...!

4

1 回答 1

1

像这样的东西?

$cat_id = 10;
$category = Mage::getModel('catalog/category')->load($cat_id);
$collection = Mage::getModel('catalog/category')->getCategories($cat_id, 0, true, true);

foreach ($collection as $cat) {
    echo $cat->getId().' '.$cat->getPosition().' '.$cat->getName().'<br/>';
}
于 2012-12-21T13:13:21.657 回答