0

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

  • first to set enable rating from admin side here – Nikhil waghela 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 – nagendra Sep 1 '17 at 8:54
0

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

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.