How to get ratings in a group count of 5 star, 4 star, 3 star, 2 star and 1 star in Magento 2.0 in form.phtml of Magento_Review template.enter image description here

  • I don't think that you can do it with 3 attributes for rating. You will need to use only 1 rating criteria first (Right now in default magento there are price, quality and value, so total rating is average of 3 criteria, which can be decimal). Commented Aug 9, 2016 at 7:35
  • Yes I am using only 1 for rating. But how we call Rating Summery in Magento 2 on rating form page. Commented Aug 9, 2016 at 9:49
  • Have you got solution for this Question? Commented Jan 31, 2017 at 5:49
  • @RonakChauhan, Yes I create custom function and query for this. Commented Jan 31, 2017 at 6:24
  • can you give me that code? Commented Jan 31, 2017 at 6:26

2 Answers 2


You have to create and call this method with your product ID. Also make sure you have only 1 rating option in admin.

public function getAllStart($pid) {
    $review = $this->_objectReview->getCollection()     //\Magento\Review\Model\Review $reviewFactory (_objectReview)
            ->addFieldToFilter('main_table.status_id', 1)
            ->addEntityFilter('product', $pid)          //$pid = > your current product ID
            ['vote' => $review->getTable('rating_option_vote')], 'main_table.review_id = vote.review_id', array('review_value' => 'vote.value')
    $review->getSelect()->order('review_value DESC');
    $review->getSelect()->columns('count(vote.vote_id) as total_vote')->group('review_value');
    for ($i = 5; $i >= 1; $i--) {
        $arrRatings[$i]['value'] = 0;
    foreach ($review as $_result) {
        $arrRatings[$_result['review_value']]['value'] = $_result['total_vote'];
    return $arrRatings;
  • it's not working if the site have multiple criterias ratings.
    – huykon225
    Commented Dec 11, 2020 at 8:00
  • admin rating change after display Error frontend "Item (Magento\Review\Model\Review) with the same ID "364" already exists."
    – Himanshu
    Commented Feb 11, 2021 at 9:32

I think what you are asking is how to get a rating summary of all of the ratings in 1.

If that is the case you simply need to call the ratings summary template.

Check out this question:

How to get rating summary in Magento 2?

Your Answer

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

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