【问题标题】:Magento Catalog Product SubCategory NameMagento 目录产品子类别名称
【发布时间】:2015-09-24 07:08:02
【问题描述】:

我正在实现 Magento 目录产品视图页面,我需要添加产品的子类别的名称。

显示类别的代码如:$_product->category->name

但我无法获取子类别名称。

【问题讨论】:

    标签: magento magento-1.7 categories product catalog


    【解决方案1】:

    要获取类别的子类别,请使用以下代码

    $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();
    }
    

    【讨论】:

    • 我需要获取选中的子分类,而不是该分类的所有分类。
    【解决方案2】:

    我通过以下方式获得子类别:

    <?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();
        }
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多