1

In my requirement, I have a review id with me by using that, I am getting complete information of that specific review by using the following code:

$review = Mage::getModel('review/review')->load($reviewId);

The above code is giving complete information but not just ratings. When I did Mage::log($review->getData()), I can see the following information which is clearly showing absence of ratings.

(
    [review_id] => 676
    [created_at] => 2014-01-31 15:19:24
    [entity_id] => 1
    [entity_pk_value] => 669
    [status_id] => 1
    [detail_id] => 675
    [store_id] => 1
    [title] => [email protected]
    [location] => Hulk mania
    [view_type] => 1
    [detail] => Hulk smash
    [nickname] => Hulk
    [customer_id] => 
    [course] => 
    [ystart] => 0
    [yend] => 0
    [stores] => Array
        (
            [0] => 0
            [1] => 1
        )

)

Please help

EDIT: I tried this which is giving all the three rating values but I was looking for percentage. and even the code is bigger and seems to be degrading performance.

$review = Mage::getModel('review/review')
                ->load($reviewId);

$data = $review->getData();
$votes = Mage::getModel('rating/rating_option_vote')
        ->getResourceCollection()
        ->setEntityPkFilter($data['entity_pk_value'])
        ->addFilter('review_id', $reviewId)
        // ->setStoreFilter(Mage::app()->getStore()->getId())
        ->load();
2
  • possible duplicate of Get ratings related to a product
    – Moose
    Commented Apr 2, 2014 at 6:05
  • @moose that is getting ratings related to a product. I am asking here getting ratings related to a review. I would have used that link if I knew product id. but here I know review id. or am I being confused?
    – Mr_Green
    Commented Apr 2, 2014 at 6:11

2 Answers 2

6

You can get the vote collection related to a review via the following code snippet. This will return you the content of the table rating_option_vote including the rating_id if that is what you are looking for.

$votesCollection = Mage::getModel('rating/rating_option_vote')
    ->getResourceCollection()
    ->setReviewFilter($reviewId)
    ->setStoreFilter(Mage::app()->getStore()->getId())
    ->load();
3
  • This is giving me the same three types of ratings with values but not a average percentage of the three. Please check my edit.
    – Mr_Green
    Commented Apr 2, 2014 at 8:15
  • @Mr_Green then sadly I think you need to join to the aggregated table with the rating id and product id you have just found from the vote collection :( Commented Apr 2, 2014 at 8:29
  • I wonder what went through those guys' heads when they didn't include the ratings in Mage::getModel('review/review'). Every single store out there wants those stars but you have to go through an extra step to get them. Commented Jan 28, 2016 at 14:31
0

Seems like the person who ask the question still have not got the answer he/she want, so let me input a bit here. To get the review + rating for a product for all store view, there are two places you need code changes

  1. Override Mage_Review_Block_Product_View#getReviewsCollection()

    if (null === $this->_reviewsCollection) {
        $this->_reviewsCollection = Mage::getModel('review/review')->getCollection()
            //->addStoreFilter(Mage::app()->getStore()->getId())
            ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
            ->addEntityFilter('product', $this->getProduct()->getId())
            ->setDateOrder();
    }
    return $this->_reviewsCollection;
    

You can see there is a store filter there, remove the line, and review will appear for every store.

  1. Above will only give you review, but not rating for each review, as those are store filter as well. Next override Mage_Rating_Model_Resource_Rating_Option_Vote_Collection#setStoreFilter($storeId)

    public function setStoreFilter($storeId)
    {
        //$this->getSelect()
        // ->join(array('rstore'=>$this->getTable('review/review_store')),
        //  $this->getConnection()->quoteInto(
        //  'main_table.review_id=rstore.review_id AND rstore.store_id=?',
        //  (int)$storeId),
        //array());
        //Override core to make rating appear every store
        return $this;
    }
    

There you have it. I am assume you know how to override Magento Core files.

1
  • I do get the answer but still thanks for this answer as well.
    – Mr_Green
    Commented Oct 13, 2017 at 5:33

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.