0

How to display all product reviews and ratings on the home page like below image?enter image description here

1
  • what you tried so far? Please at least give some try.
    – Amit Bera
    Commented Oct 22, 2019 at 11:55

1 Answer 1

1

add custom block template to your home page and add below code into phtml file

    <?php
        $_helper    = $this->helper('your_cusotm_helper_name');        
        foreach($_helper->getAllReviews() as $review):?>
            <div class='review-single col-md-12'>
                <?php echo $review['title']; ?>
            </div>
        <?php endforeach; ?>

helper >> data.php

    /**
     * @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
     */
    protected $reviewCollectionFactory;

    /**
     * @var \Magento\Tax\Api\Data\TaxClassInterfaceFactory
     */
    protected $storeManager;

    /**
     * constructor.
     * @param \Magento\Review\Model\ResourceModel\Review\CollectionFactory $reviewCollectionFactory
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     */
    public function __construct(
        \Magento\Review\Model\ResourceModel\Review\CollectionFactory $reviewCollectionFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->reviewCollectionFactory = $reviewCollectionFactory;
        $this->storeManager = $storeManager;
    }

    public function getAllReviews()
    {
        $reviewsCollection = $this->reviewCollectionFactory->create()
            ->addStoreFilter($this->storeManager->getStore()->getStoreId())
            ->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)
            ->setDateOrder();
        return $reviewsCollection;
    }

Your Answer

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

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