I've to list the best selling products and their category name. For this I'd used
$_storeId = Mage::app()->getStore()->getId();
$_products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH
))
->setOrder('ordered_qty', 'desc');
and for getting individual product:
foreach ($_products as $_product) {
//code need to be added here
}
but I'm not getting any way around to get the category name from $_product
.
I've tried
$_product->getCollection()->getCategoryIds();
but my script dies and do not execute further.
Best Answer
This is not technically a product collection of type
catalog/product
, what you need to do is:EDIT: as per comment, to limit the collection size: