<?phppublicfunctiongetTopRatedProducts($limit){$limit=(int)$limit;// retrieve all the products$products=Mage::getModel('catalog/product')->getCollection();$rated=array();foreach($productsas$product){$_product=Mage::getModel('catalog/product')->load($product->getid());$storeId=Mage::app()->getStore()->getId();// retrieve reviews data related to the current products// of the iteration$summaryData=Mage::getModel('review/review_summary')->setStoreId($storeId)->load($_product->getId());// put a subarray containing name, url and rating of the// product in our array containing the products$rated[]=array('rating'=>$summaryData['rating_summary'],'name'=>$_product->getName(),'url'=>$_product->getUrlPath());}// tell that the product's array must be ordered by rating DESCarsort($rated);// return the array with the amount of products defined by $limitreturnarray_slice($rated,0,$limit);}
So now that you are able to retrieve the products you need to put them in your Magento pages:
123456789101112131415
<?php//create the array of top rated products calling our function$products=Mage::helper('heart')->getTopRatedProducts(5);foreach($productsas$product){echo" <li> <a href='{$product['url']}' />{$product['name']} </a> </li> ";}