In the E-commerce world, customer is king because according to the survey, 81% of satisfied customers are more likely to do business with you again if they have a positive experience. Ongoing satisfaction leads to loyalty and customer loyalty is worthless. Magento facilitates customers to rate or review the product based on their satisfaction but sometimes when there are numerous products and you want to find customer satisfaction of particular product with various criteria, it becomes the trickiest job ever. That’s why, we are again back to simplify your task so you can easily find a number of reviews, average rating out of 5 and measure customer satisfaction in percentage programmatically.
Some products have their own brand value and trust base. The average ratings are badly needed when you only want people to have an overall idea of product popularity and overall user satisfaction as a purchase decider. In such cases, Magento store owners require to show average rating just to convince and encourage purchase.
To get Number of product reviews & average ratings programmatically in Magento, we need to use the small script. First, you need to create one file with below code and copy it into the root directory of your web server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<!--?php require_once('app/Mage.php'); Mage::app(); $productId ="xx"; // Enter your Product Id here $_product = Mage::getModel('catalog/product')->load($productId); $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; $avgper = 0; $totalrv = 0; $totalrvper =0; $ratings = array(); $count = 0; $star5 = 0; $star4 = 0; $star3 = 0; $star2 = 0; $star1 = 0; echo $review; if (count($reviews) > 0) { foreach ($reviews->getItems() as $review) { $mysum = 0; foreach( $review->getRatingVotes() as $vote ) { $mysum = $mysum + ($vote->getPercent()); $ratings[] = $vote->getPercent(); } $torat = $mysum/count($review->getRatingVotes()); if ($torat <= 100 && $torat > 80) { $star5 = $star5 + 1; } if ($torat <= 80 && $torat > 60) { $star4 = $star4 + 1; } if ($torat <= 60 && $torat > 40) { $star3 = $star3 + 1; } if ($torat <= 40 && $torat > 20) { $star2 = $star2 + 1; } if ($torat <= 20 && $torat >= 0) { $star1 = $star1 + 1; } } $avg = array_sum($ratings)/count($ratings); $totalsum = $star5+$star4+$star3+$star2+$star1; echo "# Review Summary #"."<br><br>"; echo "Total no of reviews : ". $totalsum."<br><br>"; echo "Average Ratings our of 5 : "; printf("%.2f", $avg*.05); echo "<br><br>"; } echo 'Average Ratings : '.$avg."%"; ?--> |
Once all set-n-up, just hit the URL and you will get the review and rating summary result in your web browser. You can even tweak this code as per your need.
Tell us your thoughts and comments down below and don’t forget to rate this blog.
Happy Scripting!
Wօhh jhst what I was searching for, thank you for putting up.
A business can only thrive if it has glad clients. Should you deal with it, you may in all probability find ways to serve your clients better.
Isn’t it default Magento 2 functionality?
The blog is related to Magento 1 not Magneto-2. That’s not easily available in Magneto1.