1

Currently my Magento store shows 'hollow' 5 star ratings for all products without ratings (which is 99.9% of products as it's a new store).

'hollow stars'

I would like to only have the star rating appear if a product has received one or more ratings.

I would like this to happen on the search results view, category product list view (same I believe) and also carousel display (such as recommended products at bottom of product details page).

The code which I believe is currently calling the stars into play on the list view is in list.phtml and is as follows:

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

BUT perhaps there's a deeper level which needs editing so they don't show on a carousel (eg recommended products) also?

I can't find any advice on this specific need anywhere and would really appreciate some help. Thanks.

  • An "easy" way would be to find the image file being used and erase the outline of the "hollow" star - this way an image is still loaded but is invisible until the other "filled" stars replace it. – Steven J Sep 14 '17 at 0:26
  • before those code, you need to put condition and into that you need to check that, Is product has any rating or not. – Dhiren Vasoya Sep 14 '17 at 2:31
  • 1
    I did think of the image replacement @StevenJ, but I think it's using Font awesome. (You couldn't have known that with the above info, sorry.) – Scotttiew Sep 14 '17 at 3:08
  • I Post answer, please check. – Dhiren Vasoya Sep 14 '17 at 4:36
0

You have to do that thing using this code.

<?php 
$ratobj =Mage::getModel('rating/rating')->getEntitySummary($_product->getId());
$ratings = $ratobj->getSum()/$ratobj->getCount();
if($ratings): ?>
<?php if($_product->getRatingSummary()):?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php else:?>
<div class="ratings">
<div class="rating-box">
<div class="rating" style="width:0%"></div>
</div>
</div>
<?php endif;?>
<?php endif; ?>
  • Thanks for your solution, I'll try all supplied solutions soon, when I can get back in and make modifications (some server maintenance means I can not go test it fully yet, sorry... long story ;) I'll see what works best, and choose an answer. Thanks again! – Scotttiew Sep 14 '17 at 22:29
0

If you want display if product have minimum one star then rating will display then try this code:

    <?php
    $storeId = Mage::app()->getStore()->getId();
    $summaryData = Mage::getModel('review/review_summary')
                        ->setStoreId($storeId)
                        ->load($_product->getId());

    if ($summaryData['rating_summary']):?>
        <div class="ratings">
            <div class="rating-box">
                <div class="rating" style="width:<?php echo $summaryData['rating_summary']; ?>%"></div>
            </div>
        </div>
    <?php endif; ?>

I think this code help you.

  • Thanks for your solution, I'll try all supplied solutions soon, when I can get back in and make modifications (some server maintenance means I can not go test it fully yet, sorry... long story ;) I'll see what works best, and choose an answer. Thanks again! – Scotttiew Sep 14 '17 at 22:29

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.