在Magento类别(产品列表)页面中,类别和属性选项显示在左侧边栏。我想按产品计数对这些项目进行排序。请问任何人都可以解释我在哪个文件中编写代码? 感谢
答案 0 :(得分:0)
尝试以下代码一次。更改您的类别ID。
<?php
$cats = Mage::getModel('catalog/category')->load(3)->getChildrenCategories();
?>
<ul>
<?php
$resourcearray = array();
foreach($cats as $category):
$proCnt = $category->getProductCount();
$proName = $category->getName();
$proUrl = $category->getUrl();
array_push($resourcearray, array('count' => $proCnt, 'name' => $proName,'url' => $proUrl));
?>
<?php endforeach;
ksort($resourcearray);
?>
<?php foreach($resourcearray as $val): ?>
<li>
<a href="<?php echo $val['url'] ?>"><?php echo $val['name'] ?>(<?php echo $val['count'] ?>)</a>
</li>
<?php endforeach;?>
</ul>