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] => Hulk@hell.com
    [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();
  • possible duplicate of Get ratings related to a product – Moose Apr 2 '14 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 Apr 2 '14 at 6:11
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();
  • 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 Apr 2 '14 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 :( – David Manners Apr 2 '14 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. – Claudiu Creanga Jan 28 '16 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.

  • I do get the answer but still thanks for this answer as well. – Mr_Green Oct 13 '17 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.