How To Get All Product Reviews By Product SKU In Magento 2
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..
Categories:
Magento2
View Comments (2)
Comment or Ask a Question
Quick Links