0

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). – Mohit Kumar Arora Aug 9 '16 at 7:35
  • Yes I am using only 1 for rating. But how we call Rating Summery in Magento 2 on rating form page. – Ashish Jagnani Aug 9 '16 at 9:49
  • Have you got solution for this Question? – Ronak Chauhan Jan 31 '17 at 5:49
  • @RonakChauhan, Yes I create custom function and query for this. – Ashish Jagnani Jan 31 '17 at 6:24
  • can you give me that code? – Ronak Chauhan Jan 31 '17 at 6:26
1

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
            ->addStoreFilter($this->_storeManager->getStore()->getId())
            ->addFieldToSelect('review_id')
    ;
    $review->getSelect()->columns('detail.detail_id')->joinInner(
            ['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;
    }
0

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, privacy policy and cookie policy

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