0

We are using this code to display Ratings & Reviews as below:

enter image description here

If suppose there is no review for a product, then we want to display text "No rating Available".

app/design/frontend/rwd/theme/template/review/product/view/list.phtml

<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
    <div class="review-heading">
        <h2>
            <?php echo $this->__('') ?>
            <span class="reviewtab">
            <?php 
        //  echo count($_items); 
            ?> 
            Ratings & Reviews
            </span>
        </h2>
        <?php echo $this->getChildHtml('toolbar') ?>
    </div>
    <dl>
    <?php foreach ($_items as $_review):?>

        <dt>
        <?php $_votes = $_review->getRatingVotes(); ?>
            <?php if (count($_votes)): ?>
            <table class="ratings-table">
                <colgroup>

                    <col class="review-value" />
                </colgroup>
                <tbody>

                    <?php foreach ($_votes as $_vote): ?>
                    <tr>
                        <th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
                        <td>
                            <div class="rating-box">
                                <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <?php endif; ?>
            <a href="<?php echo $this->getReviewUrl($_review->getId()) ?>">
                <?php echo $this->escapeHtml($_review->getTitle()) ?>
            </a>
        </dt>
        <dd>

            <?php echo nl2br($this->escapeHtml($_review->getDetail())) ?>




            <span class="review-meta">
                <?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
                /
               <?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
            </span>
        </dd>
    <?php endforeach; ?>
    </dl>

    <?php // echo $this->getChildHtml('toolbar') ?>
<?php elseif($this->getParentBlock()): ?>
    <?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>

2 Answers 2

1

As i check you have already display form for add review in tab so this tab just need to show review. so please check below code.

<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
    <div class="review-heading">
        <h2>
            <?php echo $this->__('') ?>
            <span class="reviewtab">
            <?php 
        //  echo count($_items); 
            ?> 
            Ratings & Reviews
            </span>
        </h2>
        <?php echo $this->getChildHtml('toolbar') ?>
    </div>
    <dl>
    <?php foreach ($_items as $_review):?>

        <dt>
        <?php $_votes = $_review->getRatingVotes(); ?>
            <?php if (count($_votes)): ?>
            <table class="ratings-table">
                <colgroup>

                    <col class="review-value" />
                </colgroup>
                <tbody>

                    <?php foreach ($_votes as $_vote): ?>
                    <tr>
                        <th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
                        <td>
                            <div class="rating-box">
                                <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <?php endif; ?>
            <a href="<?php echo $this->getReviewUrl($_review->getId()) ?>">
                <?php echo $this->escapeHtml($_review->getTitle()) ?>
            </a>
        </dt>
        <dd>

            <?php echo nl2br($this->escapeHtml($_review->getDetail())) ?>




            <span class="review-meta">
                <?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
                /
               <?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
            </span>
        </dd>
    <?php endforeach; ?>
    </dl>
 <?php else: ?>
   <div class="review-heading"><?php echo $this->__('No rating Available'); ?></div>
 <?php endif; ?>
</div>
2
  • 1
    hello Baby in Magento as this answerd worked ? Jul 21, 2016 at 7:18
  • so please vote as worked. Jul 21, 2016 at 7:19
1

Just replace:

<?php elseif($this->getParentBlock()): ?>
    <?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>

with:

<?php elseif($this->getParentBlock()): ?>
    <?php echo $this->__('No rating Available');?>
    <?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>

If you also don't want to show Be the first to review this product, then comment out:

<?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
7
  • sorry, that didt worked for me, can you check here under Reviews section. Jul 21, 2016 at 7:04
  • Since you have called review form in another tab, you don't need to write this line: <?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?> You can remove it. Jul 21, 2016 at 7:09
  • I have checked it in rwd theme and it is working fine here. Jul 21, 2016 at 7:10
  • I removed that line Jul 21, 2016 at 7:11
  • 1
    Glad to know that I could help. :) Jul 21, 2016 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.