显示产品属于Magento的所有类别 [英] Display ALL categories that a product belongs to in Magento

查看:123
本文介绍了显示产品属于Magento的所有类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在概念化一个新的Magento网站,将有产品包括在几个类别。我想知道的是,如果我可以显示产品在产品详细信息页面上的所有类别。我知道可以获得 类别,但是可以显示产品所属的所有类别的列表吗?

I am conceptualizing a new Magento site which will have products that are included in several categories. What I am wondering is if I can display all categories a product is in on the product detail page. I know that it is possible to get the category, but is it possible to display a list of all categories which a product belongs to?

例如,衬衫可能会包含在衬衫类别,以及设计师夏天。理想情况下,我想显示以下内容:

For example, a shirt may be included in the Shirts category, as well as in Designers and Summer. Ideally, I would like to be able to display the following:


更多来自:

More from:

   男士衬衫

   Men > Shirts

   男装>设计师>BarnabéHardy

   Men > Designers > Barnabé Hardy

   男士>夏季

   Men > Summer


推荐答案

您正在寻找的资料,例如类别名称,网址等:

This will get you the data you are looking for such as the category's name, URL, etc:

$currentCatIds = $_product->getCategoryIds();
$categoryCollection = Mage::getResourceModel('catalog/category_collection')
                     ->addAttributeToSelect('name')
                     ->addAttributeToSelect('url')
                     ->addAttributeToFilter('entity_id', $currentCatIds)
                     ->addIsActiveFilter();

foreach($categoryCollection as $cat){
  echo $cat->getName().' '.$cat->getUrl();
}

这篇关于显示产品属于Magento的所有类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆