0

次のコードをmagentoベーステンプレートファイルに入れましたview.phtml

$ category = $ _product-> getCategoryIds(); print_r($ category)

サンプルデータを使用して、Ottoman製品ページに表示されている場合、どのブレッドクラムが

 Home / Furniture / Living Room / Ottoman

出力はArray ( [0] => 22 ) 22isidLiving Roomです。Furniture and Living Room IDを取得する方法。ありがとうございました

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 に答える