1

I need to display the average of all the product reviews in magento.

I need if you can view it in this way decimal avarage

1 Answer 1

4

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);
}
1
  • @yavonz15 if you want to improve Hitesh's answer, then please add an answer yourself
    – 7ochem
    Jul 20, 2016 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.