1

I have been trying to show the rating on the category listing page. They show up if there is a rating, but I want rating to show even if there are no reviews (no stars).

In the list.phtml page i see:

<?php echo $block->getReviewsSummaryHtml($_product, $templateType, true); ?>

I also see the function

    public function aroundGetReviewsSummaryHtml(
    ListProduct $subject,
    callable $proceed,
    \Magento\Catalog\Model\Product $product,
    $templateType = false,
    $displayIfNoReviews = false)
{
    return $this->_helper->getCategoryShowReviews($subject->getMode())
        ? $proceed($product, $templateType, $displayIfNoReviews)
        : '';
}

I have tried a lot of things but can not get anything to show if there are no reviews. The end of the functions has a variable $displayIfNoReviews, but if i set this to true, still doesn't show.

Anyone have any ideas I can try?

EDIT 1: I have changed the summary_short file with the code below. But its showing 0% now. Not the ratings.

    <div class="product-reviews-summary short empty">
    <?php $rating = 0 ;?>
    <div class="rating-summary">
        <span class="label"><span><?php /* @escapeNotVerified */ echo __('Rating') ?>:</span></span>
        <div class="rating-result" title="<?php /* @escapeNotVerified */ echo $rating; ?>%">
            <span style="width:<?php /* @escapeNotVerified */ echo $rating; ?>%"><span><?php /* @escapeNotVerified */ echo $rating; ?>%</span></span>
        </div>
    </div>

    <div class="reviews-actions">
        <a class="action add" href="<?php /* @escapeNotVerified */ echo $urlForm; ?>">
            <?php /* @escapeNotVerified */ echo __('Be the first to review this product') ?>
        </a>
    </div>
</div>

EDIT 2: Percent

<?php

/** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */

// @codingStandardsIgnoreFile

?>

getReviewsUrl() . '#reviews'; ?> getReviewsUrl() . '#review-form'; ?> getReviewsCount()): ?> getRatingSummary(); ?>
   <div class="product-reviews-summary short<?php echo !$rating ? ' no-rating' : ''?>">
    <?php if ($rating):?>
        <div class="rating-summary">
            <span class="label"><span><?php /* @escapeNotVerified */ echo __('Rating') ?>:</span></span>

            <div class="rating-result__stars 111">
                <?php
                $half_star_id = round( (int)$rating / 20 );
                for($i = 0; $i < 5; $i++){
                    if( $i < $half_star_id ) {
                        echo '<span class="rating-star__full"></span>';
                    }
                    if( $i == $half_star_id ) {
                        echo '<span class="rating-star__half"></span>';
                    }
                    if( $i > $half_star_id ) {
                        echo '<span class="rating-star__empty"></span>';
                    }
                } ?>
            </div>

            <div class="rating-result__text">
                <span style="width:<?php /* @escapeNotVerified */ echo $rating; ?>%"><span><?php /* @escapeNotVerified */ echo $rating; ?>%</span></span>
            </div>
        </div>
    <?php endif;?>

    <div class="reviews-actions">
        <a class="action view" href="<?php /* @escapeNotVerified */ echo $url ?>"><?php /* @escapeNotVerified */ echo $block->getReviewsCount() ?>&nbsp;<span><?php /* @escapeNotVerified */ echo($block->getReviewsCount() == 1) ? __('Review') : __('Reviews') ?></span></a>
    </div>
</div>
getDisplayIfEmpty()): ?>
<div class="product-reviews-summary short empty">
    <?php $rating = 0 ;?>
    <div class="rating-summary">
        <span class="label"><span><?php /* @escapeNotVerified */ echo __('Rating') ?>:</span></span>
        <div class="rating-result" title="<?php /* @escapeNotVerified */ echo $rating; ?>%">
            <span style="width:<?php /* @escapeNotVerified */ echo $rating; ?>%"><span><?php /* @escapeNotVerified */ echo $rating; ?>%</span></span>
        </div>
    </div>

    <div class="reviews-actions">
        <a class="action add" href="<?php /* @escapeNotVerified */ echo $urlForm; ?>">
            <?php /* @escapeNotVerified */ echo __('Be the first to review this product') ?>
        </a>
    </div>
</div>
getRatingSummary(); ?>
   <div class="product-reviews-summary short<?php echo !$rating ? ' no-rating' : ''?>">
    <?php if ($rating):?>
        <div class="rating-summary">
            <span class="label"><span><?php /* @escapeNotVerified */ echo __('Rating') ?>:</span></span>

            <div class="rating-result__stars 11">
                <?php
                $half_star_id = round( (int)$rating / 20 );
                for($i = 0; $i < 5; $i++){
                    if( $i < $half_star_id ) {
                        echo '<span class="rating-star__full"></span>';
                    }
                    if( $i == $half_star_id ) {
                        echo '<span class="rating-star__half"></span>';
                    }
                    if( $i > $half_star_id ) {
                        echo '<span class="rating-star__empty"></span>';
                    }
                } ?>
            </div>

            <div class="rating-result__text">
                <span style="width:<?php /* @escapeNotVerified */ echo $rating; ?>%"><span><?php /* @escapeNotVerified */ echo $rating; ?>%</span></span>
            </div>
        </div>
    <?php endif;?>
    <div class="reviews-actions">
        <a class="action view" href="<?php /* @escapeNotVerified */ echo $url ?>"><?php /* @escapeNotVerified */ echo $block->getReviewsCount() ?>&nbsp;<span><?php /* @escapeNotVerified */ echo($block->getReviewsCount() == 1) ? __('Review') : __('Reviews') ?></span></a>
    </div>
</div>
0

If you want to show rating on those products which does not have any rating then you need to some changes at template phtml files also there are no need to use aroundGetReviewsSummaryHtml. Also make <?php echo $block->getReviewsSummaryHtml($_product, $templateType, true); ?>

  • Thank you for the reply. However, its showing 0% when I add the code. I have updated my post to include your code (EDIT 1). Anyway to get the stars? – Jerrod Sep 3 '17 at 7:35
  • Any chance I can get help on this still? Its showing percent instead of stars. – Jerrod Sep 6 '17 at 23:22
  • The above worked, just shows the %. I need the stars if possible. – Jerrod Sep 11 '17 at 0:28
  • Star should be shown here. Please check the on default Magento – Amit Bera Sep 11 '17 at 0:54
  • Default magento shows this empty stars on the catalog page? I have attached a screenshot of the issue on EDIT 2. If it has reviews, it shows stars. If not, a percent. – Jerrod Sep 12 '17 at 6:04

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.