Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

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

. . .

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