Back to Top

How To Get All Product Reviews By Product SKU In Magento 2

Updated 28 February 2024

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..

Searching for an experienced
Magento 2 Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • kk
  • Subho
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home