0

我将以下代码放入 magento 基本模板文件view.phtml中。

$categories = $_product->getCategoryIds(); print_r($类别)

使用示例数据,当在Ottoman产品页面上时,哪个面包屑是

 Home / Furniture / Living Room / Ottoman

输出是Array ( [0] => 22 ) 22 是Living Roomid。如何获得Furniture and Living Room 身份证。谢谢你

4

2 回答 2

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
}
于 2012-08-23T05:46:40.507 回答
-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());
}
于 2012-08-23T06:38:06.433 回答