0

Im trying to find out if there are reviews for the product the user is on within the review/form.phtml template file.

The idea is if the product has reviews give the review form a particular class to position it on the page, if the product doesn't have any reviews, don't change to class name and leave it where it is.

Does this make sense?

So my question is how to i retrieve amount of reviews for a product in the review/form.phtml file?

thanks

Edit

I have tried this statement:

<?php if( count( $this->getReviewsCollection() > 0 ) ): ?>
    <div class="form-add got-reviews-form">
<?php else: ?>
    <div class="form-add no-reviews-form">
<?php endif; ?>

This doesn't give me fatal errors which means its along the right tracks, but theres a big problem in the ract that it always returns true, so even if the product doesn't have reviews, i still get the

got-reviews-form

class. Any ideas why this could be?

Thanks

1
  • Have you tried Evgeni's answer with same code. Commented Aug 3, 2014 at 5:49

3 Answers 3

1

You have a typo in your code, bracket is in wrong place:

<?php if( count( $this->getReviewsCollection() > 0 ) ): ?>

It should be:

<?php if( count( $this->getReviewsCollection() ) > 0  ): ?>

However, it's better to use this code if you only want to check size of the collection:

<?php if( $this->getReviewsCollection()->getSize() > 0  ): ?>
0

You are interested in the class Mage_Review_Block_Form. Unfortunately there isn't any method that will give you that info out of the box, so you will need to get that from the parent block.

inside the reviews/form.phtml try this

  <?php if($this->getLayout()->getBlock('product.info.product_additional_data')->getReviewsCollection()->getSize()) : ?>

    //add class
 <?php else: ?>

 <?php endif; ?> 
2
  • Hi mate, thanks for the answer! It looks like its along the right lines because im not longer getting fatal errors! but for some reason the test isn't working, see my edit. Thanks
    – Tom Burman
    Commented May 4, 2014 at 6:01
  • @Tom have you tried this anwser, With this same code Commented Aug 3, 2014 at 5:48
0

You can use

getTotalReviews($product_id, true, Mage::app()->getStore()->getId())

on review object to find total review.

Pass true in second argument to get approved review.

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.