Magento Forum

   
Page 1 of 2
Making customer reviews appear on the product info page
 
Sintax
Member
 
Total Posts:  58
Joined:  2008-02-18
Hungary
 

Hi,

I want to get the customer reviews to appear on the product info page rather than having to click the link for the reviews. I want to create a tabbed layout for the page.

Here is what I did:

I modified catalog/product/view.phtml and removed this:

<?=$this->helper('review/product')->getSummaryHtml($_productnull1)?>

Then I tracked down how to get the review count and the rating average:

if( !$_product->getRatingSummary() ) {
        Mage
::getModel('review/review')->getEntitySummary($_productMage::app()->getStore()->getId());
    
}
    $numReviews 
$_product->getRatingSummary()->getReviewsCount();
    
$ratingSummary $_product->getRatingSummary()->getRatingSummary();

Then I wanted to list all the reviews in the page:

<?
                $productId 
$_product->getId();
                
$_collectionX Mage::getModel('review/review')->getCollection();
                
$_collectionX->addStoreFilter(Mage::app()->getStore()->getId())->addStatusFilter('approved')->addEntityFilter('product'$productId)->setDateOrder();
                
?>
                
<div class="collateral-box dedicated-review-box" id="customer-reviews">
            <
div class="head">
                <
h4><?=$this->__('Customer Reviews')?></h4>
            </
div>
        
            <
ol style="margin-top:15px;">
        
<?foreach$_collectionX->getItems() as $_reviewX ):?>
                
<li>
                
<? var_dump($_reviewX); ?>
                    
<a href="<?=$this->getReviewUrl($_reviewX->getId())?>"><strong><?=$_reviewX->getTitle()?></strong></a<?=$this->__('Review by %s'$_reviewX->getNickname())?>
                    
<table class="ratings-list" cellspacing="0">
                        <
tbody>
                       
<?foreach$_reviewX->getRatingVotes() as $_voteX ):?>
                        
<tr>
                            <
td class="label"><strong><?=$_voteX->getRatingCode()?></strong></td>
                            <
td>
                                <
div class="rating-box">
                                    <
div class="rating" style="width: <?=$_voteX->getPercent()?>%;"></div>
                                </
div>
                            </
td>
                        </
tr>
                        
<?endforeach;?>
                        
</tbody>
                    </
table>
                    <
p><?=nl2br($_reviewX->getDetail())?> <?=$this->__('(Posted on %s)'$this->formatDate($_reviewX->getCreatedAt()), 'long')?></p></li>
                <
li>
        
<?endforeach;?>
            
</ol>
Which only partially worked. I got the review date, the reviewer and the content, however I couldn’t get the rating, since it kept complaining the the foreach parameter is incorrect ( $_reviewX->getRatingVotes() as $_voteX ).

Does anyone know what could be wrong?

::Sintax

 
Magento Community Magento Community
Magento Community
Magento Community
 
danieln
Sr. Member
 
Avatar
Total Posts:  131
Joined:  2007-11-08
Mainz, Germany
 

I would also like to know how to do this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
danieln
Sr. Member
 
Avatar
Total Posts:  131
Joined:  2007-11-08
Mainz, Germany
 

Hello Sintax,

In case you’re still looking for the solution, here it is:
( you were missing the ->addRateVotes())
catalog/product/view.phtml

<?php $_reviews Mage::getModel('review/review')->getCollection()
                                    ->
addStoreFilter(Mage::app()->getStore()->getId())
                                   ->
addEntityFilter('product'$_product->getId())
                                   ->
addStatusFilter('approved')
                                   ->
addRateVotes()
                                   ->
setDateOrder(); ?>
    <?php 
foreach ($_reviews->getItems() as $_review): ?>
        <?php 
foreach( $_review->getRatingVotes() as $_vote ): ?>
                <?php 
echo $_vote->getRatingCode() ?>
                
<div class="rating-box">
                    <
div class="rating" style="width: <?php echo $_vote->getPercent() ?>%;"></div>
                </
div>
            
<?php endforeach; ?>
        
<div class="review_details">
            
<?php echo $_review->title ?>
            
...
        </
div>
    
<?php endforeach; ?>

Best regards,
Daniel

 
Magento Community Magento Community
Magento Community
Magento Community
 
katiek648
Member
 
Total Posts:  33
Joined:  2008-04-10
 

I’m looking to also place the reviews/rating on the product page. However, I tried the code above, but there is obviously additional items to add in that code here:

<div class="review_details">
            
<?php echo $_review->title ?>
            
...
        </
div>
Can someone show me what additional code I need? I would like for everything to show up like it is on the review page with title, reviewed by, rating, description, posted date.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
danieln
Sr. Member
 
Avatar
Total Posts:  131
Joined:  2007-11-08
Mainz, Germany
 

Try

<?php Zend_Debug::dump($_review); ?>
Then you will see what else you can get smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

It is preferred to use methods to retrieve object data:

$_review->getTitle();

To see all object data use ->debug() method:

<pre><?php echo print_r($_review->debug());?></pre>

 
Magento Community Magento Community
Magento Community
Magento Community
 
lisali
Enthusiast
 
Avatar
Total Posts:  888
Joined:  2008-04-28
London, UK
 

Eh - I am a bit confused now...could someone please, please post a complete guide on how to do this?

Ideally - this should be configurable from the back-end, but for now - how would I go about adding the review to the product info page?

Many thanks!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
lisali
Enthusiast
 
Avatar
Total Posts:  888
Joined:  2008-04-28
London, UK
 

Anyone? Please? Any updates?

smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
benaschkade
Jr. Member
 
Total Posts:  10
Joined:  2008-09-03
 

Updates? Please? I spent the whole day trying to make this work and utterly failed. Doh!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Consofas
Jr. Member
 
Total Posts:  29
Joined:  2008-05-21
 

Full code I have used in catalog/product/view.phtml around line 109

<?php $_reviews Mage::getModel('review/review')->getCollection()
                                    ->
addStoreFilter(Mage::app()->getStore()->getId())
                                   ->
addEntityFilter('product'$_product->getId())
                                   ->
addStatusFilter('approved')
                                   ->
addRateVotes()
                                   ->
setDateOrder(); ?>
        
<div class="collateral-box dedicated-review-box" id="customer-reviews">
            <
div class="head">
                <
h4>Customer Reviews</h4>
            </
div>
            
<?php if($_reviews->count()): ?>
            <?php 
foreach ($_reviews->getItems() as $_review): ?>
                <?php 
foreach( $_review->getRatingVotes() as $_vote ): ?>
                        <?php 
echo $_vote->getRatingCode() ?>
                        
<div class="rating-box">
                            <
div class="rating" style="width: <?php echo $_vote->getPercent() ?>%;"></div>
                        </
div>
                    
<?php endforeach; ?>
                
<div class="review_details">
                    <
h4><a href="<?=$this->getReviewUrl($_review->getId())?>"><?php echo $_review->title ?></a></h4>
                    <
p><?=nl2br($_review->getDetail())?></p>
                    <
p><?=$this->__('(Posted on %s)'$this->formatDate($_review->getCreatedAt()), 'long')?> <?=$this->__('Review by %s'$_review->getNickname())?></p>
                </
div>
            
<?php endforeach; ?> 
                
<p><a href="http://www.powermillblender.com/store/review/product/list/id/7/#review-form">Add your review</a></p>
            
<?php else: ?>
                
<p><a href="http://www.powermillblender.com/store/review/product/list/id/7/#review-form">Be the first to review this product</a></p>
            
<?php endif; ?>
        
</div>
Unfortunately on the actual review page the reviews now show up twice!
Once I figure that one out I will update this post.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Consofas
Jr. Member
 
Total Posts:  29
Joined:  2008-05-21
 

Thanks to sintax and danieln who started this, Not sure I could have figured it out without your code in the posts above.

 
Magento Community Magento Community
Magento Community
Magento Community
 
benaschkade
Jr. Member
 
Total Posts:  10
Joined:  2008-09-03
 

Thanks guys for help! Ya’ll rock!

 
Magento Community Magento Community
Magento Community
Magento Community
 
dosplus
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2008-08-14
 

Unfortunately on the actual review page the reviews now show up twice!
Once I figure that one out I will update this post.

Anybody found the answer to this problem.... i have the same problem.

Thanks, Martin

 
Magento Community Magento Community
Magento Community
Magento Community
 
bloggleme
Sr. Member
 
Avatar
Total Posts:  101
Joined:  2008-05-06
 

I also am experiencing double ratings! This is ridiculous. And it looks retarded to our visitors… Is there a fix yet?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

According to my test, actually, it’s not duplicating the ratings. The problem is that labels for ‘quality’, ‘price’ and ‘value’ are not showing up in the frontend but in source code (likely to do with absolute positioning of the stars and z-index).
So, the choice would be whether to show summary of ratings or full description of ratings.

I am trying to test out the full description of ratings. Will post back if I get any further.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

The code ‘ <?php echo $_vote->getRatingCode() ?>’ generates rating’s labels too, and likely due to the absolute positioning they are overlapped by the rating stars.

So one quick fix for you guys is using table instead of div for rating section.

<?php foreach ($_reviews->getItems() as $_review): ?>
<table class="ratings-list" cellspacing="0">
<?php foreach ($_review->getRatingVotes() as $_vote): ?>
<tr>
<td class="label"><strong><?php echo $_vote->getRatingCode() ?></strong></td>
<td>
<div class="rating-box">
<div class="rating" style="width: <?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>

Oh my buddha! I can’t believe I suggest using table!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2