As OpenCart 2.3 to make a rating of the goods as at Wildberries?

Hello. Searched for a plugin but found none. As possible on the product page to make a rating of the product in this way?
5e9803e60adf6679585235.jpeg
Now in the template are passed as a standard, only such variables:
Overall rating rounded to the nearest unit: $rating
Number of ratings: $rating_data

How do I get the number of evaluations with a rating of 1, 2 rathinam, etc.?
April 19th 20 at 12:16
1 answer
April 19th 20 at 12:18
Solution
Could make this (OpenCart 3.0.3.2) :
In the controller catalog/controller/product/product.php
After the line
$data['rating'] = (int)$product_info['rating'];
Insert
// Expanded rating
$this->load->model('catalog/review');
 $review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
 $estimations = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id']);

 $one = 0;
 $two = 0;
 $three = 0;
 $four = 0;
 $five = 0;
 $rating_sum = 0;

 foreach ($estimations as $estimation){
 ($estimation['rating'] == '1') && $one++;
 ($estimation['rating'] == '2') && $two++;
 ($estimation['rating'] == '3') && $three++;
 ($estimation['rating'] == '4') && $four++;
 ($estimation['rating'] == '5') && $five++;

 $rating_sum += $estimation['rating'];
}

 $data['expanded_rating'][] = array(
 'one' => round((100/$review_total) * $one),
 'two' => round((100/$review_total) * $two),
 'three' => round((100/$review_total) * $three),
 'four' => round((100/$review_total) * $four),
 'five' => round((100/$review_total) * $five),
 'rating' => round($rating_sum / $review_total, 1),
 'total' => $review_total
 );

Next in the file
catalog/view/theme/default/template/product/product.twig

after the line
<p>{% for i in 1..5 %}
 {% if rating < i %}<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-1x"></i></span>{% else %}<span class="fa fa-stack"><i class="fa fa-star fa-stack-1x"></i><i class="fa fa-star-o fa-stack-1x"></i></span>{% endif %}
 {% endfor %} <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;">{{ reviews }}</a> / <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;">{{ text_write }}</a></p>
 <hr>

Insert
{% for rating in expanded_rating %}
 <p>1 - {{ rating.one }}%</p>
 <p>2 - {{ rating.two }}%</p>
 <p>3 - {{ rating.three }}%</p>
 <p>4 - {{ rating.four }}%</p>
 <p>5 - {{ rating.five }}%</p>
 the <h3>Overall rating {{ rating.rating }}</h3>
 <p>based On {{ rating.total }} reviews</p>
 {% endfor %}
 <hr>


Should get so
5e98c4b75cc24861087497.png
Class, thank you. Check it out. - pamela.Dibbe commented on April 19th 20 at 12:21
If my answer helped you, mark it as the solution. - josianne commented on April 19th 20 at 12:24
@josianne, made, tweaked code for opencart 2.3 so:
In the controller catalog/controller/product/product.php added check for reviews, otherwise, if not, then comes the error of division by zero. Replaced this:
if ($review_total>0) {
 $data['expanded_rating'] = array(
 'one' => round((100/$review_total) * $one),
 'two' => round((100/$review_total) * $two),
 'three' => round((100/$review_total) * $three),
 'four' => round((100/$review_total) * $four),
 'five' => round((100/$review_total) * $five),
 'rating' => round($rating_sum / $review_total, 1),
 'total' => $review_total
);
 } else {
 $data['expanded_rating'] = ";
 }


And in the file catalog/view/theme/default/template/product/product.tpl did so:
<?php if ($expanded_rating != ") { ?>
<p>1 - <?php echo $expanded_rating['one']; ?>%</p>
<p>2 - <?php echo $expanded_rating['two']; ?>%</p>
<p>3 - <?php echo $expanded_rating['three']; ?>%</p>
<p>4 - <?php echo $expanded_rating['four']; ?>%</p>
<p>5 - <?php echo $expanded_rating['five']; ?>%</p>

the <h3>Overall rating - <?php echo $expanded_rating['rating']; ?></h3>
<p>On the basis <?php echo $expanded_rating['total']; ?> reviews</p>
<?php } ?>
- pamela.Dibbe commented on April 19th 20 at 12:27

Find more questions by tags ocStoreOpenCart