Customised Magento review summary

There is little doubt that product reviews are popular with online shoppers, and are playing an increasingly important role in purchasers' buying decisions. Magento includes a solid feature set for implementing product reviews and can show them on various pages that include product listings. You may find that you want to customise the way these reviews are displayed, but the best way to do this may not be immediately obvious.

The standard review summary text for products without reviews is:

In cases with one or more existing reviews it shows the rating followed by some links, as seen in this example:

And if you inspect the relevant phtml files you will find this code, which is responsible for inserting the review summary html:

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

But what if you needed to make changes to this? If you want to change the look for all instances of the review summary you can simple change the review summary phtml file, namely:

/template/review/helper/summary.phtml

If, on the other hand you would like to have a different looking review summary in some cases, whilst leaving the default look for others, you can indeed do this and it is very easy. Magento actually provides a shorter version of the review summary, but this is not obvious from the existing code. For some reason the second argument in the getReviewsSummaryHtml function call is incorrectly set to 'false' when it really isn't a boolean, but is actually a keyword for a review summary template. Magento comes with a shorter version of the review summary which you can access by simply replacing the false in the second argument with "short", like this:

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

Now if there is a review for a product it will be appear like this

and if you want to edit this template, you can find it here

/template/review/helper/summary_short.phtml

You can go a step further and add your custom templates as well. However, to do this you will need to edit one Magento core file and you will need to add your own phtml template.

First, add your own phtml file in the template/review/helper/directory. Probably the best thing to do here is to make a copy of the existing summary.phtml file and modify it to fit your needs. Let's say you called your new file myreview.phtml.

You need to add a reference to this template (a keyword and the path to your phtml template) in the following core file:

/app/code/core/Mage/Review/Block/Helper.php

in the $_availableTemplates array. Once you have added the necessary line, the top of the file should look like this:

class Mage_Review_Block_Helper extends Mage_Core_Block_Template
{
    private $_availableTemplates = array(
        'default' => 'review/helper/summary.phtml',
	'short'   => 'review/helper/summary_short.phtml'
	'myreview'=> 'review/helper/myreview.phtml'
    );
 
	public function getSummaryHtml($product, $templateType, $displayIfNoReviews)
	{
...

Note the usual warning that you should not edit the actual Magento core file, but should first copy it to your local directory. The file to edit is:

/app/code/local/Mage/Review/Block/Helper.php

Your template is ready to go. To use it in your html code simply insert the following line:

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

Comments

How to put html code in magento reviews?

Great article thanks.
What about removing the review summary off any product listings, so reviews only appear on the product page it self?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <perl>, <php>, <python>, <ruby>, <xml>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.