Magento:获取当前商店/网站的父类别

时间:2012-07-05 01:44:42

标签: magento categories product

我正在使用this code在面包屑中显示产品的父类别。

不幸的是,这不适用于多商店设置,其中产品另外被分配给当前商店中不存在的类别。例: 在this product page上,面包屑链接到“Minikameras”类别,该类别实际上是另一个网站/商店的类别。

仅显示活动网站/商店类别的最佳方式是什么?

2 个答案:

答案 0 :(得分:3)

使用以下代码获取当前商店的根类别。

<?php Mage::app()->getStore()->getRootCategoryId() ?>

答案 1 :(得分:0)

      <?
       Mage::app('store', 'website');//enter your store and website here
       $products = Mage::getModel('catalog/product')->getCollection();
       $categories = $product->getCategoryIds();
       foreach($categories as $k => $_category_id): 
       $_category = Mage::getModel('catalog/category')->load($_category_id);
       $cat_name = $_category->getName();
       $cat_url =  $_category->getUrl();
       endforeach;
       ?>

这是另一种方法。它将列出类别名称和类别URL。您所要做的就是进入商店和网站。希望它有所帮助。

相关问题