magento - Show product reviews in review summary
I am trying to redesign the review summary for the product page, so it shows the list of reviews and the form to add a new review.
The form works, but the list does not. I add the summary from view.phtml like this:
<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
My summary.phtml file return this error:
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
for this line:
<?php $_items = $this->getReviewsCollection()->getItems();?>
My summary.phtml file looks like this:
<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>
You have to do a little bit of work in your layout.xml. The guys at Classy Llama make it easy:
http://www.magentocommerce.com/boards/viewthread/41882/#t142654
精彩评论