0

Magento how to get rating star by review id

enter image description here

I used the following code

$ratingCollection = Mage::getModel('rating/rating_option_vote')
     ->getResourceCollection()
     ->setReviewFilter($_review->getId())
     ->setStoreFilter(Mage::app()->getStore()->getId())
     ->addRatingInfo(Mage::app()->getStore()->getId())
     ->load()
     ->getItems();

     $ratings = array();
     foreach($ratingCollection as $item){
        $ratings[]=$item->getValue();
    }

but I am getting array summary as 12, 15 but I need %

Thanks

2

The rating_option_vote table saves to vote option for a particular rating type.

This table has review_id as the foreign key which references to review table.

Please check screenshots for reference.

enter image description here

enter image description here

Update: Code for getting ratings per review:

<?php
$reviewcollection = Mage::getModel('review/review')->getCollection()
                ->addStoreFilter(Mage::app()->getStore()->getId())
                ->setDateOrder()->addRateVotes();
        $_items = $reviewcollection;
// echo "<pre>";print_r($_items->getData());echo "</pre>";
        foreach ($_items as $_review) {
            $_votes = $_review->getRatingVotes();
            if (count($_votes)) {
                foreach ($_votes as $_vote) {
                    echo $this->escapeHtml($_vote->getRatingCode());
                    echo "<br/>";
                    echo $_vote->getPercent();
                }
            }
        }
?>

Update: You can also try below code:

<?php
$votesCollection = Mage::getModel('rating/rating_option_vote')
    ->getResourceCollection()
    ->setReviewFilter(1)
    ->setStoreFilter(Mage::app()->getStore()->getId())
    ->load();
// echo "<pre>";print_r($votesCollection);echo "</pre>";
    foreach ($votesCollection as $vote) {
        # code...
        echo "<pre>";print_r($vote);echo "</pre>";
    }
?>
  • can you please check the updated question, thanks i used the above code – Raghu Mar 5 '18 at 9:40
  • @Raghu, please see my updated answer. – Mohit Kumar Arora Mar 5 '18 at 12:42

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.