Search code examples
magentomagento-1.9

Ignore Pending Product Reviews in Magento


By default, Magento only displays existing ratings/reviews on category page template app/design/frontend/base/default/template/catalog/product/list.phtml like this:

<?php if ($_product->getRatingSummary()): ?>
    <?php echo $this->getReviewsSummaryHtml($_product, 'short'); ?>
<?php endif; ?>

I adopted this in my own theme and included a reasonable fallback so as not to break the flow/layout of the page. However, if there are 0 reviews and a review is posted but not approved, nothing is displayed (see attached image).

Pending Product Review Bug

<?php if ($_product->getRatingSummary()): ?>
    <?php echo $this->getReviewsSummaryHtml($_product, 'short'); ?>
<?php else: ?>
<div class="ratings">
  <div class="rating-box">
    <div class="rating" style="width: 0%;"></div>
  </div>
  <span class="amount"><a href="<?php echo $_product->getProductUrl(); ?>#client-reviews">0 <?php echo $this->__('Review(s)'); ?></a></span>
</div>
<?php endif; ?>

Thanks!


Solution

  • Added an additional condition which, while not the prettiest solution, does the trick.

    <?php if ($_product->getRatingSummary() && $_product->getRatingSummary()->getData('reviews_count') > 0): ?>
        <?php echo $this->getReviewsSummaryHtml($_product, 'short'); ?>
    <?php else: ?>
        <div class="ratings">
            <div class="rating-box">
              <div class="rating" style="width: 0%"></div>
            </div>
            <span class="amount"><a href="<?php echo $_product->getProductUrl(); ?>#client-reviews">0 <?php echo $this->__('Review(s)'); ?></a></span>
        </div>
    <?php endif; ?>