0

I've searched for the answer to this, but I'm only seeing answers to Magento 1. I need to display all of the approved Reviews on a single page. Preferably a CMS page. How do I go about this?

The best code I've seen for this is:

<?php 
$review_collection = Mage::getModel('review/review')
->getResourceCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder()
->addRateVotes();
 ?>

<?php foreach($review_collection as $review): ?>

<div class='review-single col-md-12'>
<div class="box-review-single">
<p id="title-review">
    <?php echo $review['title'];  ?>
</p>
<p id="detail-review">
    <?php echo $review['detail'];  ?>
</p>
<p id="nick-review">
    <?php echo $review['nickname'];  ?>
</p>
</div>
</div>

From this Magento forum page: Display all reviews on one page

But it is for Magento 1.9 and I'm not sure it will work in Magento 2.1.7 which is what I am using. Further more, I am not sure what pieces of the code go where (ie: PHP into a phtml or PHP file - but what directory do I place it in, Do I place any code in the XML section of the CMS page, etc)

Any help would be greatly appreciated.

Thanks, A

1 Answer 1

2

Try this method for Magento 2

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $_reviewsColFactory = $objectManager->get("\Magento\Review\Model\ResourceModel\Review\CollectionFactory");
    $_storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
    $reviewsCollection = $_reviewsColFactory->create()
                                            ->addStoreFilter($_storeManager->getStore()->getStoreId())
                                            ->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)
                                            ->setDateOrder();

    foreach($reviewsCollection as $review):?>
        <div class='review-single col-md-12'>
            <div class="box-review-single">
                <p id="title-review">
                    <?php echo $review['title'];  ?>
                </p>
                <p id="detail-review">
                    <?php echo $review['detail'];  ?>
                </p>
                <p id="nick-review">
                    <?php echo $review['nickname'];  ?>
                </p>
            </div>
        </div>
    <?php endforeach; ?>
3
  • Thank you so much. I placed your code into a .PHTML file and uploaded it into the Framework directory under /Magento_Review/templates. Then I called the PHTML file from a CMS page that I created, using the following code pasted into the "Content" section of the CMS page: {{block class="Magento\Framework\View\Element\Template" template="Magento_Review::totalreviews.phtml"}} - Hope this helps anyone else looking for this solution. THANKS Ranganathan.S!!! Oct 21, 2017 at 5:50
  • i tried this but nothing displayed in the page(i have reviews in review_detail) Oct 1, 2018 at 16:38
  • Pls share your Magento version and did you follow the steps in above comment? Oct 4, 2018 at 4:08

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.