Magento – How to filter product collection using ratings

collection-filteringfiltered-navmagento-1.8

I want to filter the product collection using "Ratings". As it is not an attribute of products how can i do that?

$collection = Mage::getModel('catalog/product')->getCollection()
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('type_id', 'configurable')
             ->addAttributeToSort('name', 'asc');

I want to do Ratings filtering for the above collection.

Thanks in advance.

Best Answer

Try this.

$collection = Mage::getModel('catalog/product')->getCollection();
$reviews = Mage::getModel('review/review')
            ->getResourceCollection()
            ->addStoreFilter(Mage::app()->getStore()->getId()); 

foreach($collection as $product)
{   
    $productId = $product->getId();
    $reviews->addEntityFilter('product', $productId)
            ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
            ->setDateOrder()
            ->addRateVotes();
}