我将以下代码放入magento基本模板文件view.phtml
。
$ categories = $ _product-> getCategoryIds(); 的print_r($类别)
使用示例数据,在Ottoman
产品页面上,哪个痕迹是
Home / Furniture / Living Room / Ottoman
输出为Array ( [0] => 22 )
,22为Living Room
id。如何获得Furniture and Living Room
id。谢谢
答案 0 :(得分:2)
$categories=$_product->getCategoryIds();
foreach ($categories as $category)
{
$info = Mage::getModel('catalog/category')
->load($category)
->getParentCategory();
echo $info->getId(); //display category ID
//var_dump($info->debug()); # display model contents
}
答案 1 :(得分:-1)
以下是获取所有类别ID的方法:
//load root category
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootCategory = Mage::getModel('catalog/category')
->load($rootCategoryId);
//load all children categories of the root category
$childrenCategories = $rootCategory->getChildrenCategories();
现在你可以像这样访问他们的ID:
foreach ($childrenCategories as $category) {
var_dump($category->getId());
}