gpt4 book ai didi

php - Magento : showing sub sub categories in same order as in admin backend tree structure

转载 作者:搜寻专家 更新时间:2023-10-31 21:38:16 27 4
gpt4 key购买 nike

我使用 Magento 1.7.2,并显示当前类别的子类别和子子类别列表。我的问题是子类别不遵循与管理后端树结构中相同的顺序。看起来他们是通过他们的 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>

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

最佳答案

是这样的吗?

$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/>';
}

关于php - Magento : showing sub sub categories in same order as in admin backend tree structure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13989610/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com