4

After upgrading Magento from 2.1.3 to 2.2.3 my reviews are not showing up on the Frontend > Product View > Reviews Tab.

The following container is empty (I assume the reviews should be supposed to be there):

<div id="product-review-container" data-role="product-review"></div>

Reviews not showing up on reviews tab

  • The reviews are approved in the backend and showing up there as usual
  • The review form is working as expected

Additional info:

/magento_2.1.3/vendor/magento/module-review/view/frontend/templates/review.phtml

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @description:
 *
 */
?>
<?php
    $_items = $block->getReviewsCollection()->getItems();
    $format = $block->getDateFormat() ?: \IntlDateFormatter::SHORT;
?>
<?php if (count($_items)):?>
<div class="block review-list" id="customer-reviews">
    <div class="block-title">
        <strong><?php /* @escapeNotVerified */ echo __('Customer Reviews') ?></strong>
    </div>
    <div class="block-content">
        <div class="toolbar review-toolbar">
            <?php echo $block->getChildHtml('toolbar') ?>
        </div>
        <ol class="items review-items">
        <?php foreach ($_items as $_review):?>
            <li class="item review-item" itemscope itemprop="review" itemtype="http://schema.org/Review">
                <div class="review-title" itemprop="name"><?php echo $block->escapeHtml($_review->getTitle()) ?></div>
                <?php if (count($_review->getRatingVotes())): ?>
                    <div class="review-ratings">
                    <?php foreach ($_review->getRatingVotes() as $_vote): ?>
                    <div class="rating-summary item" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
                        <span class="label rating-label"><span><?php echo $block->escapeHtml($_vote->getRatingCode()) ?></span></span>
                        <div class="rating-result" title="<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
                            <meta itemprop="worstRating" content = "1"/>
                            <meta itemprop="bestRating" content = "100"/>
                            <span style="width:<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
                                <span itemprop="ratingValue"><?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%</span>
                            </span>
                        </div>
                    </div>
                    <?php endforeach; ?>
                    </div>
                <?php endif; ?>
                <div class="review-content" itemprop="description">
                    <?php echo nl2br($block->escapeHtml($_review->getDetail())) ?>
                </div>
                <div class="review-details">
                    <p class="review-author">
                        <span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Review by')?></span>
                        <strong class="review-details-value" itemprop="author"><?php echo $block->escapeHtml($_review->getNickname()) ?></strong>
                    </p>
                    <p class="review-date">
                        <span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Posted on') ?></span>
                        <time class="review-details-value" itemprop="datePublished" datetime="<?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?>"><?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?></time>
                    </p>
                </div>
            </li>
        <?php endforeach; ?>
        </ol>
        <div class="toolbar review-toolbar">
            <?php echo $block->getChildHtml('toolbar') ?>
        </div>
    </div>
</div>
<?php endif;?>
1

For me this was the issue.

Magento is not grabbing the proper alias name for the tabs. For example, if you look at this file vendor/magento/module-review/view/frontend/layout/catalog_product_view.xml you will see the name of the block is reviews.tab and the alias is properly defined as reviews.

Next, if you look at this file you will see it is depending on the element id of tab-label-reviews vendor/magento/module-review/view/frontend/templates/review.phtml. If you take a look at your tab source code you probably have tab-label-reviews.tab set for the id of the tab element which is wrong and why the reviews are not loading because the element doesn't exist.

The file that generates the tab element id's is located here: vendor/magento/module-catalog/view/frontend/templates/product/view/details.phtml (assuming you don't have a theme that overrides it like Ultimo which in that case is found here: app/design/frontend/Infortis/base/Infortis_Base/templates/product/view/details.phtml.

What I did to fix this quickly was to simply override the file into my theme and then strip the .tab text from the element id like so.

....
<div class="data item title"
data-role="collapsible" id="tab-label-<?php /* @escapeNotVerified */ echo str_replace('.tab', '', $alias); ?>">
  <a class="data switch"
    tabindex="-1"
    data-toggle="trigger"
    href="#<?= /* @escapeNotVerified */ $alias ?>"
    id="tab-label-<?= /* @escapeNotVerified */ $alias ?>-title">
    <?= /* @escapeNotVerified */ $label ?>
  </a>
</div>
....

Notice the str_replace() function which removes the extra .tab text which fixes the element ID's incorrect format.

Please don't forget to mark as the correct answer if this was your case also.

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.