Magento 2 Rating Collection by Review ID

magento2product-reviewratings

Magento 2 how to get the data from 'rating_option_vote' by review_id using objectmanager?

Best Answer

You can use 'Magento\Review\Model\ResourceModel\Rating\Option\Vote\Collection'. Find the code for getting the collection and filtering it by 'review_id'.

<?php 
use Magento\Framework\App\Bootstrap;  
require __DIR__ . '/app/bootstrap.php';  
$bootstrap = Bootstrap::create(BP, $_SERVER);  
$obj = $bootstrap->getObjectManager();  
$state = $obj->get('Magento\Framework\App\State');  
$state->setAreaCode('frontend');  

$reviewId = 5; //custom review id.  
$ratingCollection = $obj->get('Magento\Review\Model\ResourceModel\Rating\Option\Vote\Collection')->addRatingInfo()->addOptionInfo()->addRatingOptions()->addFieldToFilter('review_id',$reviewId);  
print_r($ratingCollection->getData());