On magento product view page, i'm trying to order upsell products by best selling / more rating
On a search i found that this code will work to get order product collection by best seling,
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect(array('name', 'price', 'small_image')) //edit to suit tastes
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder('ordered_qty', 'desc'); //best sellers on top
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
print_r($products->getData());
I have two issues where to add this code
& how about adding set order by rating too
?
Any help is much appreciated.