cancel
Showing results for 
Search instead for 
Did you mean: 

How To Get Rating Summary In Magento 2?

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How To Get Rating Summary In Magento 2?

I need to show a rating with stars on my cms template on the frontend.

 

Any idea?

 

 

1 REPLY 1

Re: How To Get Rating Summary In Magento 2?

Hello @Shiwani Miglani 

 

Yes, you can get ratingSummary by using ReviewFactory ! below i am posting the code for the same :

 

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());
    $ratingSummary = $product->getRatingSummary()->getRatingSummary();

    return $ratingSummary;
}

For more details refer this link - https://magento.stackexchange.com/questions/123568/how-to-get-rating-summary-in-magento-2

if issue solved,Click Kudos & Accept as Solution