在 Magento 中忽略待处理的产品评论

Ignore Pending Product Reviews in Magento

默认情况下,Magento 在类别页面模板 app/design/frontend/base/default/template/catalog/product/list.phtml 上显示现有 ratings/reviews,如下所示:

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

我在自己的主题中采用了这一点,并包含了一个合理的回退,以免破坏页面的 flow/layout。 但是,如果有 0 条评论 评论已发布但 批准,则不会显示任何内容(参见附图).

<?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; ?>

谢谢!

添加了一个附加条件,虽然不是最漂亮的解决方案,但可以解决问题。

<?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; ?>