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
Want to point out that the solution by @Rao is the best if you have a product object to get category ID's from as it makes only one SQL call.
If you just have category id's, you can do the following:
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('name') //you can add more attributes using this
->addAttributeToFilter('entity_id', array('in'=>array(1,2,3)));
foreach($categories as $_cat){
$holder[]= $_cat->getName();
}
Where array(1,2,3) are your categories. Note that the array has integers, not string values, I found that SQL can be picky about that.
Also wanted to point out that solutions pulling one category at a time are very inefficient as it makes an SQL call for every iteration of the loop e.g.:
foreach(..){
Mage::getModel('catalog/category')->load($categoryId);
}