Product – Load All Reviews and Ratings Using Product ID

productratings

I want to load all reviews and all ratings of a specific product using product id so i have made a module but problem is that i am not able to load detail reviews and detail rating of any specific product using product id only. i want to use it on categories page. i want this

enter image description here
and i have completed jquery part only product loading part is left please help me as soon as possible. I want to use foreach command not any other command.

Best Answer

you use below script to get all reveiew and rating .

 <?php
require_once('app/Mage.php');
Mage::app();

$_product=Mage::getModel('catalog/product')->load(1);

$productId = $_product->getId();
$reviews = Mage::getModel('review/review')
                ->getResourceCollection()
                ->addStoreFilter(Mage::app()->getStore()->getId())
                ->addEntityFilter('product', $productId)
                ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
                ->setDateOrder()
                ->addRateVotes();

$avg = 0;
$ratings = array();
if (count($reviews) > 0) {
    foreach ($reviews->getItems() as $review) {
        foreach( $review->getRatingVotes() as $vote ) {
            Mage::log('2 if');
            Mage::log($vote->getData());
            $ratings[] = $vote->getPercent();
        }
    }

    $avg = array_sum($ratings)/count($ratings);
}
echo 'avg'.$avg;

?>