I am trying to take product reviews programmatically, filter them by product and pull out the rating stars.
I can get the text of the reviews (getDetail()) without any problems and in fact I see all the review texts including the creation dates. What I can't see is the rating score of the review. Whenever I try to print out getRatingVotes the value always returns 0. As if the ratings are not saved but they are actually there. This is my code:
<?php
$product_id = $_product->getId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$rating = $objectManager->create('\Magento\Review\Model\Rating');
$review = $objectManager->create('\Magento\Review\Model\Review');
$storeManager = $objectManager->create("\Magento\Store\Model\StoreManagerInterface");
$_ratingSummary = $rating->getEntitySummary($product_id);
$ratingCollection = $review->getResourceCollection()
->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)
->addEntityFilter('product', $product_id)
->setDateOrder()
->addRateVotes();
$review_count = count($ratingCollection); // How many review in that specific product
foreach($ratingCollection->getItems() as $ratingItem){
echo $ratingItem->getDetail().' '.'<br/>';
if(count($ratingItem->getRatingVotes()) > 0){
foreach($ratingItem->getRatingVotes() as $_vote){
echo $_vote->getPercent().'<br/>';
}
}
}
?>
How come I can't see the ratings score for the review?