【发布时间】:2015-02-13 04:40:45
【问题描述】:
我正在尝试在我的 magento 商店中显示一个菜单,该菜单仅显示我所在的当前类别树的第 3 级类别。
我的类别树分为两条路径:
- 默认
- 出售
- 项目 1
- 第 2 项
- 修复
- 项目 1
- 第 2 项
- 出售
当我属于任何销售类别时,我只想显示第 3 级销售,反之亦然,当我属于任何维修类别时。
下面的代码显示了 3 级类别,但仅用于修复,无论我碰巧属于哪个类别。
<?php
$layer = Mage::getSingleton('catalog/layer');
/* @var $category Mage_Catalog_Model_Category */
$categories = $layer->getCurrentCategory();
$categories = Mage::getModel('catalog/category')
->setStoreId(Mage::app()->getStore()->getId())
->getCollection()
// magic is prepared here..
->addAttributeToSelect('*')
// then the magic happens here:
->addAttributeToFilter('level', array('eq' => 3))
->load();
?>
<?php foreach ($categories as $cat): ?>
谢谢。
模组
【问题讨论】:
标签: php magento magento-1.7