Is there a build-in feature in Magento 2 by which top rated products can be shown? If not, then how can i display it in left side of category page. Any type of sample code would be helpful for me :)

1 Answer 1

public function getRatingSummary()

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $reviewFactory = $objectManager->get(\Magento\Review\Model\ReviewFactory::class);
    $storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
    $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
    $collection = $productCollection->create()
    $rating = array();
    foreach ($collection as $product) {
        $reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
        $ratingSummary = $product->getRatingSummary()->getRatingSummary();
            $rating[$product->getId()] = $ratingSummary;
    return $rating;
  • Can you please post template file too? Sep 3, 2020 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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