0

On a product page of our site when customers leave reviews with star ratings, the start rating summary (average) is displayed at the top of the product page.

enter image description here

But I've noticed that when we change the store view the star rating summary disappears from the top of the page and only the rating links remain.

enter image description here

I've looked at the code in: app/design/frontend/base/default/template/review/helper/summary.phtml

<?php if ($this->getRatingSummary()):?>
    <div class="rating-box">
        <div class="rating" style="width:<?php echo $this->getRatingSummary() ?>%"></div>
    </div>
<?php endif;?>

And $this->getRatingSummary() returns '0' rather than '100' when I change the store view from the store view in which the customer left their review in.

Is there anyway I can display the star ratings summary no matter what the store view is?

On the admin panel I've set the review to be visible in all store views i.e. Catalog > Reviews and Ratings > Customer Reviews > All Reviews

1 Answer 1

0

I solved this by creating a new review/helper/summary.phtml template file in our custom theme and updated the code to:

<?php
$reviewSummary = Mage::getModel('review/review_summary');
$storeStructure = Mage::getSingleton('adminhtml/system_store')->getStoresStructure();
$productId = $this->getProduct()->getId();
$avgRating = 0;
$cumulativeRating = 0;
$storesWithRatings = 0;
foreach($storeStructure as $websiteStructure){
    foreach($websiteStructure[children] as $storeInfo){
        $storeID = $storeInfo[value];
        array_push($storeIds,$storeID);
        $currentRating = $reviewSummary->setStoreId($storeID)->load($productId)->getRatingSummary();
        if ($currentRating) {
            $storesWithRatings++;
        }
        $cumulativeRating = $cumulativeRating + $currentRating;
    }
}

if ($cumulativeRating && $storesWithRatings) {
    $avgRating = $cumulativeRating / $storesWithRatings;
}
?>
<div class="ratings">
    <?php if ($avgRating):?>
        <div class="rating-box">
            <div class="rating" style="width:<?php echo $avgRating ?>%"></div>
        </div>
    <?php endif;?>

This code is iterating over an array of each of the stores, getting the rating score for each of the products and putting the average rating from each of the stores into a variable called $avgRating.

A drawback to this approach is that even if a review is not visible in the current store view, it's rating will be added to the avgRating.

I think that in Magento when you set a review to be visible in a store view, the same should be applied to the ratingSummary.

Similarly, to have the star ratings to appear on the review itself no matter what the store view I followed this approach: https://magento.stackexchange.com/a/17731/6549

1
  • This seems to be overkill. You can remove store filter for the review query. Mage_Review_Model_Review#getEntitySummary(), comment the line where it said ->setStoreId($storeId). Of course, you should override, instead of modify core. But that should be it.
    – Thang Pham
    Oct 13, 2017 at 3:39

Your Answer

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

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