Leon van der Veen
Leon van der Veen

Reputation: 1672

magento summary rating of customers review

I'm using Magento and I want to accomplish the following:

Customers can write a review an rate my product. They can rate several options as price, quality etc.

When they rate the product the review and rating shows at the productpage. For each rate options i see that stars for the rating but what I want is a summary total of the rating of that customer.

So this total rating has to become the same as the total rating on the product listing.

I hope someone can help me with this one.

Thanks in advance!

Upvotes: 1

Views: 5266

Answers (1)

Magento Guy
Magento Guy

Reputation: 2493

In *magento/app/design/frontend/base/[your_theme]/template/review/product/view/list.phtml*

You will see the following foreach loop:

<?php foreach ($_votes as $_vote): ?>
  <tr>
    <th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
    <td>
      <div class="rating-box">
        <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
      </div>
    </td>
  </tr>
<?php endforeach; ?>

This loops through each vote and outputs it as a star rating.

Change it to the following:

<?php
  $_percent = 0;
  foreach ($_votes as $_vote) {
    $_percent = $_percent + $_vote->getPercent();
  }
  $_percent = $_percent / count($_votes);
?>
<tr>
  <th>Aggregate rating:</th>
  <td>
    <div class="rating-box">
      <div class="rating" style="width:<?php echo $_percent ?>%;"></div>
    </div>
  </td>
</tr>

Instead of displaying each vote, you're now calculating the aggregate percentage, and only outputting one vote.

Upvotes: 6

Related Questions