I"m trying to retrieve all reviews and ratings for a product. I'm not entirely sure how this could be accomplished. anyone care to help a brutha out?

I am currently trying to use:

            $reviews = Mage::getModel('review/review')
                ->addFieldToFilter('entity_id', 1)
                ->addFieldToFilter('entity_pk_value', $productId)

            $reviewData = array();
            if (count($reviews) > 0) {
                foreach ($reviews as $r) {
                    foreach ($r->getRatingVotes() as $vote) {
                        $ratings[] = $vote->getPercent();

However, ratings[] is null when i dump the variables.

  • 1
    your traced down that $reviews and $vote are not empty/null? Nov 5, 2014 at 15:14
  • @StefanGregori I just checked those variables and noticed that getPercent() did not have parentheses in my production environment (I copied the above from a text editor). It appears the bug was found to be in my very own visual processing Virtual Machine :D Your comment was that which brought this bug to my attention though, thank you! Nov 5, 2014 at 15:36

1 Answer 1


If you can also get this data for all products as a collection:

class Amasty_Review_Model_Mysql4_Collection extends  Mage_Review_Model_Mysql4_Review_Product_Collection
// approved reviews plus visible in catalog products plus url revrites data
public function addVisiblityFilter()
    $store = Mage::app()->getStore();

        ->addAttributeToSelect(array('name','visibility'), 'inner');


    $urCondions = array(
        'ur.category_id IS NULL',

        array('ur' => $this->getTable('core/url_rewrite')),
        join(' AND ', $urCondions),
        array('url' => 'request_path')

    return $this;

public function addRatingData()
    $ratingTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_option_vote');
        ->joinLeft(array('rat' => $ratingTable),
            'rat.review_id = rt.review_id',
            array('av_rating' => new Zend_Db_Expr('AVG(rat.percent)')))

    return $this;        


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.