How can programatically get product rating and review in product collection in Magento 2.

  • first to set enable rating from admin side here Aug 10 '17 at 11:10
  • it was already enabled..i want to get the rating programatically
    – srg
    Aug 11 '17 at 4:15
  • please confirm whether you are looking for ratnigs and reviews collection by using sku Sep 1 '17 at 8:54

You can just pass the product object and get the rating summary for specific product.

protected $_reviewFactory;

public function __construct(
    \Magento\Review\Model\ReviewFactory $reviewFactory,
) {
    $this->_reviewFactory = $reviewFactory;

public function getRatingSummary()
    $this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());

    return $product->getRatingSummary()->getRatingSummary();
  • i got the product rating...but how can i get the product review by customers..?
    – srg
    Sep 5 '17 at 4:39

You can use below code to get products reviews and rating summary

$sku = 'test-product';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create("Magento\Catalog\Model\Product")->loadByAttribute('sku', $sku); //use load($producID)
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStoreId = $storeManager->getStore()->getId();

Rating summary

$reviewFactory = $objectManager->create('Magento\Review\Model\Review');
$reviewFactory->getEntitySummary($product, $currentStoreId);    
$ratingSummary = $product->getRatingSummary()->getRatingSummary();


$review = $objectManager->get("Magento\Review\Model\ResourceModel\Review\CollectionFactory");

$collection = $review->create()->addStoreFilter(


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.