magento - 在评论摘要中显示产品评论

时间:2011-07-14 17:04:40

标签: php magento

我正在尝试重新设计产品页面的评论摘要,因此它会显示评论列表和添加新评论的表单。

表单有效,但列表没有。我在view.phtml中添加了这样的摘要:

<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>

我的summary.phtml文件返回此错误:

  

Fatal error: Call to a member function getItems() on a non-object in /home/content/41/6755141/html/keepwell/buy/app/design/frontend/fvm/default/template/review/helper/summary.phtml

这一行:

<?php $_items = $this->getReviewsCollection()->getItems();?>

我的summary.phtml文件如下所示:

<div id="column-one-left">

<?php if ($this->getReviewsCount()): ?>

    <p class="title-noline"><?php echo $this->__('Customer Reviews') ?></p>

    <div id="customer-reviews">

    <?php $_items = $this->getReviewsCollection()->getItems();?>
    <?php if (count($_items)):?>
        <?php echo $this->getChildHtml('toolbar') ?>
        <dl>
        <?php foreach ($_items as $_review):?>

            <div class="review">
                <p class="review-title"><?php echo $this->htmlEscape($_review->getTitle()) ?></p>
                <p class="review-name"><?php echo $this->__('by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?></p>
                <p class="review-body"><?php echo nl2br($this->htmlEscape($_review->getDetail())) ?></p>
            </div>
            <hr class="review" />

            <dt>
                <a href="<?php echo $this->getReviewUrl($_review->getId()) ?>"><?php echo $this->htmlEscape($_review->getTitle()) ?></a> 
            </dt>
            <dd>
                <?php $_votes = $_review->getRatingVotes(); ?>
                <?php if (count($_votes)): ?>
                <table class="ratings-table">
                    <col width="1" />
                    <col />
                    <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; ?>
                <?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
                <small class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
            </dd>
        <?php endforeach; ?>
        </dl>
        <?php echo $this->getChildHtml('toolbar') ?>
    <?php endif;?>

        <div class="review">

            <p class="review-title">This is the Review Title / Summary</p>
            <p class="review-name">by John Q. Doe</p>
            <p class="review-body">Nunc hendrerit, nisi eget adipiscing hendrerit, enim mauris elementum nibh, nec ornare nisi neque in quam. Vivamus ac ligula a felis hendrerit euismod. Etiam condimentum semper massa, ac bibendum diam lacinia ut. Nullam porttitor porttitor mi in sodales. Ut a vestibulum eros.</p>
        </div>

        <hr class="review" />

    </div>

    <hr/>
    <hr/>

    <div class="ratings">

        <?php if ($this->getRatingSummary()):?>
            <div class="rating-box">
                <div class="rating" style="width:<?php echo $this->getRatingSummary() ?>%"></div>
            </div>
        <?php endif;?>

        <p class="rating-links">
            <a href="<?php echo $this->getReviewsUrl() ?>"><?php echo $this->__('%d Review(s)', $this->getReviewsCount()) ?></a>
            <span class="separator">|</span>
            <a href="<?php echo $this->getReviewsUrl() ?>#review-form"><?php echo $this->__('Add Your Review') ?></a>
        </p>

    </div>

<?php elseif ($this->getDisplayIfEmpty()): ?>
    <p class="title-noline"><?php echo $this->__('Be the first to review this product') ?> >></p>
<?php endif; ?>

</div>


<div id="column-one-right">

<?php  echo $this->getLayout()->createBlock('review/form')->setBlockId('product.review.form')->toHtml();  ?>

</div>

1 个答案:

答案 0 :(得分:2)

你必须在layout.xml中做一些工作。 Classy Llama的家伙们很容易:

http://www.magentocommerce.com/boards/viewthread/41882/#t142654

相关问题