5
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStoreId = $storeManager->getStore()->getId();
$rating = $objectManager->get("Magento\Review\Model\ResourceModel\Review\CollectionFactory");
$reviewFactory = $objectManager->create('Magento\Review\Model\Review');

$collection = $rating->create()->addStoreFilter(
    $currentStoreId
    )->addStatusFilter(
    \Magento\Review\Model\Review::STATUS_APPROVED
    )->addEntityFilter(
    'product',
    $product->getId()
    )->setDateOrder();
    $reviewlist = $collection->getData();
    foreach ($reviewlist as $review) 
    {
        echo "<pre/>";
        print_r($review);
    }

#######################################################

Output
    [review_id] => 
    [created_at] => 
    [entity_id] => 
    [entity_pk_value] => 
    [status_id] => 
    [detail_id] => 
    [title] => 
    [detail] => 
    [nickname] => 
    [customer_id] => 
    [entity_code] => 

In that I can not get the review star per review with the help of object manager. enter image description here I want highlighted box value

  • first of all, objectmanager is a bad idea to implement. – Shyam Krishna Sreekumar Jan 31 '18 at 10:20
  • I know that, but can you help with my issue?@ShyamKrishnaSreekumar – Kushal Jan 31 '18 at 10:24
3

Try to use bellow code in your phtml file You should not use the ObjectManager directly!

<?php
$productId = 'your_product_id';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$reviewFactory = $objectManager->create('Magento\Review\Model\Review');
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
$storeManager  = $objectManager->create('\Magento\Store\Model\StoreManagerInterface');
$storeId = $storeManager->getStore()->getStoreId();
$reviewFactory->getEntitySummary($product, $storeId);

$ratingSummary = $product->getRatingSummary()->getRatingSummary();
$reviewCount = $product->getRatingSummary()->getReviewsCount();
?>
<?php if($ratingSummary){ ?>
<div class="product-reviews-summary short">
    <div class="rating-summary">
        <div title="<?php echo (int)$ratingSummary; ?>%" class="rating-result">
            <span style="width:<?php echo (int)$ratingSummary; ?>%"><span><?php echo (int)$ratingSummary; ?>%</span></span>
        </div>
    </div>
    <div class="reviews-actions">
        <?php echo __('('.$reviewCount.') Reviews'); ?>
    </div>
</div>
<?php } ?>
|improve this answer|||||
  • I used this code and get an overall rating amount, but i want individual rating value and also updated question.@Chander Shekhar – Kushal Jan 31 '18 at 11:57
2
I found one link that helps to get a collection of each review
    <?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');  

    $reviewId = 5; //custom review id.  
    $ratingCollection = $obj->get('Magento\Review\Model\ResourceModel\Rating\Option\Vote\Collection')
                       ->addRatingInfo()
                       ->addOptionInfo()
                       ->addRatingOptions()
                       ->addFieldToFilter('review_id',$reviewId);  
    print_r($ratingCollection->getData());
|improve this answer|||||
1

you need to call $collection->load()->addRateVotes();, than get ratings for each review by calling $review->getRatingVotes();

|improve this answer|||||

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.