0

This question already has an answer here:

In the below code i am getting the rating percentage .How can i get the review title, description, nickname and submitted date.

public function ProductReview()
 {
    $_productID = 70;
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $_product= $objectManager->create("Magento\Catalog\Model\Product")->load($_productID);
    $_review=$objectManager->create("Magento\Review\Model\Review");
    $_reviewFact=$objectManager->get("Magento\Review\Model\ReviewFactory");
    $_reviewFact->create()->getEntitySummary($_product, 1);  
     // Below code will get the rating summary
  $rat=$_product->getRatingSummary()->getRatingSummary();
 return $rat;
 }

marked as duplicate by Prince Patel, Ben Crook, Keyul Shah, liyakat, Amit Bera Sep 9 '17 at 14:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Please try the below code in test script in the root folder of magento2

<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

ini_set('display_errors', 1);
echo "All reviews of the product </br>";



$sku = '24-MB02';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create("Magento\Catalog\Model\Product")->loadByAttribute('sku', $sku); //use load($producID) if you have product id
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStoreId = $storeManager->getStore()->getId();
$rating = $objectManager->get("Magento\Review\Model\ResourceModel\Review\CollectionFactory");

$collection = $rating->create()->addStoreFilter(
            $currentStoreId
        )->addStatusFilter(
            \Magento\Review\Model\Review::STATUS_APPROVED
        )->addEntityFilter(
            'product',
            $product->getId()
        )->setDateOrder();
echo "<pre>";
print_r($collection->getData()); //Get all review data of product
  • :Nagaraju Kasa: I have a small doubt here how can we get the rating(star) by each customer.? – srg Sep 14 '17 at 9:18
  • 1
    hi @srg i hope u r looking for this. please check this link magento.stackexchange.com/questions/187282/… – Nagaraju Kasa Sep 18 '17 at 4:57
  • hi @srg if u r satisfied with my answer please do upvote for an encouragement thanks – Nagaraju Kasa Sep 18 '17 at 4:58
  • thanks @srg please rise the upvote so that it will useful for others – Nagaraju Kasa Sep 18 '17 at 11:40
  • 1
    : i have upvoted that comment. – srg Sep 19 '17 at 5:32

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