How To Get All Product Reviews By Product SKU In Magento 2- Here I’m going to explain you how you can get all product reviews by product sku.
$sku = 'test-product'; // product sku
//product is an instance of Magento\Catalog\Model\Product class
$product = $this->_product->loadByAttribute('sku', $sku); //you can also use load($id) if you know product id
// rating is an instance of Magento\Review\Model\ResourceModel\Review\CollectionFactory class
$rating = $this->_ratingCollection;
$collection = $rating->create()
->addStatusFilter(
\Magento\Review\Model\Review::STATUS_APPROVED
)->addEntityFilter(
'product',
$product->getId()
)->setDateOrder();
echo "<pre>";
print_r($collection->getData());
In this way you can get all reviews of a product by product sku or id.
Thanks..
2 comments
How to get rating value per customer for a product in Magento 2
I want: customers :name1,
Rating: 70
Customer:name 2,
Rating:40