magento 2 rating collection by review id?
-
11-10-2020 - |
Question
Magento 2 how to get the data from 'rating_option_vote' by review_id using objectmanager?
Solution
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());
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange