【发布时间】:2015-09-24 07:08:02
【问题描述】:
我正在实现 Magento 目录产品视图页面,我需要添加产品的子类别的名称。
显示类别的代码如:$_product->category->name
但我无法获取子类别名称。
【问题讨论】:
标签: magento magento-1.7 categories product catalog
我正在实现 Magento 目录产品视图页面,我需要添加产品的子类别的名称。
显示类别的代码如:$_product->category->name
但我无法获取子类别名称。
【问题讨论】:
标签: magento magento-1.7 categories product catalog
要获取类别的子类别,请使用以下代码
$your_category_id = '2334'; // category_id whose subcategory you want to fetch
$subcats = Mage::getModel('catalog/category')->getCategories($your_category_id);
foreach ($subcats as $sub) {
echo $sub->getName();
}
【讨论】:
我通过以下方式获得子类别:
<?php
if (Mage::registry('current_product')) {
if ($_product) {
$categoryIds = $_product->getCategoryIds();
$cat_id = $categoryIds[0]; ----> pass the level of sub catgeory to the array index
$category = Mage::getModel('catalog/category')->load($cat_id);
$cat_name = $category->getName();
}
}
?>
【讨论】: