4

短いコード行が必要です。私は次のようなカテゴリを持っています

  • 猫-1
    • サブキャット-1
    • サブキャット-2
  • 猫-2
    • サブキャット-3
    • サブカテゴリ-4

Sub-Cats ページで、ルート カテゴリの ID を取得する必要があります。「Sub-Cat-1」のように、「Cat-1」の ID を取得する必要があります。子カテゴリ ページで言うことができます。親カテゴリの ID が必要です。「abc.com/Sub-Cat-1」のような短い URL を使用しており、URL には index.php もルート カテゴリもありません。Magento-1.4.1 を使用しています。私を助けてください。前もって感謝します。

4

4 に答える 4

5

私は解決策を得ました。

echo $cat_idd = $this->getCurrentCategory()->getParentCategory()->getId(); 
于 2012-07-29T18:42:02.413 に答える
4

次のように使用してみてください:

echo $subCategory->getParentId();
于 2012-07-29T08:12:52.763 に答える
2
// to get the category ID by product id

$productObj = Mage::getModel('catalog/product')->load($product_id);
$categoryIds =  $productObj->getCategoryIds();
于 2013-03-09T13:04:13.933 に答える
1
//Display all categories.

function get_categories(){

    $category = Mage::getModel('catalog/category'); 
    $tree = $category->getTreeModel(); 
    $tree->load();
    $ids = $tree->getCollection()->getAllIds(); 
    $arr = array();
        if ($ids){ 
            foreach ($ids as $id){ 
                $cat = Mage::getModel('catalog/category'); 
                $cat->load($id);
                $arr[$id] = $cat->getName();
        } 
}

return $arr;

}


 $arr =  get_categories();
 $arr = array_flip($arr);




//print the array 

それが誰かを助けることを願っています。

于 2013-03-09T12:35:48.883 に答える