How do I get categories for a product in Magento

后端 未结 6 2201
情书的邮戳
情书的邮戳 2021-01-31 16:12

I\'m trying to add product_type to my Magento Google Base output based on the product\'s categories, but I seem to be unable to. I have the following code:

// Ge         


        
6条回答
  •  半阙折子戏
    2021-01-31 16:32

    Using the source link dropped by Rao above I actually found a better answer:

    $product = Mage::getModel('catalog/product')->load($productId);
    
    $cats = $product->getCategoryIds();
    foreach ($cats as $category_id) {
        $_cat = Mage::getModel('catalog/category')->load($category_id) ;
        echo $_cat->getName();
    } 
    

提交回复
热议问题