I need to display the average of all the product reviews in magento.
1 Answer
This code might help you:
$reviews = Mage::getModel('review/review')->getResourceCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)->setDateOrder()->addRateVotes();
$avg = 0;
$totalrv = 0;
$totalrvper =0;
$ratings = array();
if (count($reviews) > 0) {
foreach ($reviews->getItems() as $review) {
foreach( $review->getRatingVotes() as $vote ) {
$totalrv = $totalrv+$vote->getValue();
$totalrvper = $totalrvper + $vote->getPercent();
}
}
$totalrv= ($totalrv/3)/4;
$totalrvper = ($totalrvper/3)/4;
$avgrate = round($totalrv, 1);
}
-
@yavonz15 if you want to improve Hitesh's answer, then please add an answer yourself– 7ochemCommented Jul 20, 2016 at 13:14