How do I get categories for a product in Magento

后端 未结 6 2284
情书的邮戳
情书的邮戳 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:27

    Rao's solution tries to load all the attributes which means lots of queries and joins but you only need a product_id to load it's categories. So you can do this:

      $product = Mage::getModel("catalog/product")->setId($productId);
      $categories = $product->getCategoryCollection();
    

    This will not load the product and will give you the categories.

提交回复
热议问题