Get product review info (independent) of review page

Featured Image

Here at Inchoo, we are working on a private project, that should see daylight any time soon. One of the requirements we had is to show product review info on pages independent of product review page. Let’s say you wish to show review info on home page for some of the products. After few weeks with working with Magento, one learns how to use the model stuff directly from view files. Although this might not be the “right” way, it’s most definitely the fastest way (and I doubt most of your clients would prefer any other :), especially if it’s some minor modification).

Here is a code to retrieve the product review info:

<?php

$storeId    = Mage::app()->getStore()->getId();

$summaryData = Mage::getModel(‘review/review_summary’)
->setStoreId($storeId)
->load($_product->getId());

/* @var $summaryData Mage_Review_Model_Review_Summary */

/*

array(
['primary_id'] => 147
['entity_pk_value'] => 166
['entity_type'] => 1
['reviews_count'] => 1
['rating_summary'] => 80
['store_id'] => 1
)
*/

?>

Just be sure to pass it the right product id number. Cheers…

20
Top

Care to rate this post?

Author

Branko Ajzele

Ex Inchooer

Worked at Inchoo as a Backend Developer/CTO from 2008 to 2013

Other posts from this author

Discussion 20 Comments

Add Comment
  1. sergiu

    where do i have to insert this code ?

  2. Sam

    How do you echo out the rating summary as the ’5 stars’ using this method?

  3. Sam

    As always, answered by own question just after I posted!

    $storeId = Mage::app()->getStore()->getId();
    $summaryData = Mage::getModel(‘review/review_summary’)
    ->setStoreId($storeId)
    ->load($_product->getId());
    echo ‘
    getRatingSummary().’%”>
    ‘;

  4. As always, you at Inchoo provide kick-ass Magentutorials ;-)

  5. tom

    i was to open a review page on my e commerce site and put a new product on the spotlight for customers to review / or just add the current data from the product page

    where do i insert this code? i tried via the CMS but it’s not working

    any suggestions ?

  6. How to get the review success message from the session on review page?

    Please provide the solution..Thanks in Advance.

  7. How to display Recent Review on my home page?

  8. max

    how do i add a product review pagination?

  9. getStore()->getId();
    $summaryData = Mage::getModel(‘review/review_summary’)
    ->setStoreId($storeId)
    ->load($_product->getId())->getRatingSummary();
    ?>

    Get stare rating summary

  10. But how to get star rating for each individual review ??

  11. As always answered my own question :-)

     $reviewcollection =  Mage::getModel('review/review')->getCollection()
    						->addStoreFilter(Mage::app()->getStore()->getId())
    						->addStatusFilter('approved')
    						->addRateVotes()
    						->addEntityFilter('product', $this->getProduct()->getId())
    						->setDateOrder();
    

    * added ->addRateVotes()

  12. mark

    hi,
    Any one please tell me the pagination for the reviews in front end…

  13. Tung

    Hi, now i doing select all products that have review highest, or vote % highest, but when select with ->join, magento generate sql statement ok, but collection not ok. More detail, i need order by rating_summary but collection products order by entity_id. Actual i don’t understand. This is my code:

    			$collection = Mage::getModel('catalog/product')
    					->getResourceCollection()
    					->addAttributeToSelect('*')
    					->setOrder('rating_summary', 'desc')
    					->setPageSize($this->getLimit())
    					->load()
    					;
    		$collection->getSelect()
    				->join(array('res'=>'review_entity_summary'), 'res.entity_pk_value = e.entity_id', array('res.rating_summary'));
    		$collection->getSelect()->where('store_id ='.$this->getStore())
    				;
    		$collection->getSelect()->order('res.rating_summary desc');		 

    Hope for soon reply. Thank

  14. Harita

    i want to display reviews of new product on home page? please tell me where to put this code?…

  15. Yudha

    @Harita, if you get an answer, let me know. Thanks

  16. valy

    I’m getting a blank page when using the code from this post. Is there anything i’m missing?

  17. This is really good. I was using this information about getting the reviews several times so far. Thank you

  18. Guillermo

    Hi there, where this code should be added?, i get a blank page when i used this code.

    Thanks

  19. how to display top rated products in home page

  20. Alex

    Hi! I want to display review form for each product on category page..how can I do it? Could anyone help? By this moment I can see review form template for each product, but then I press submit review nothing happens and in backend review didn’t appear. Thanks in advance.

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top