2

I need display all approved reviews on one CMS page.

I tried below code but not working .

$collection = Mage::getModel('catalog/product')->getCollection();

foreach ($collection as $product){
    //var_dump($product);
    $storeId = Mage::app()->getStore()->getId();
    $summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($product->getData('entity_id'));
}

4 Answers 4

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

foreach($review_collection as $review){


    //echo "<pre>";
    echo $review['detail'];   //Here you can get the review wrote by customer
    //exit;



}
1

Try the entity filter addEntityFilter:

    $collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product) {
    $storeId = Mage::app()->getStore()->getId();

    $summaryData = Mage::getModel('review/review_product')->getCollection()
        ->addEntityFilter('product', $product->getEntityId())

     foreach($summaryData as $review)
         {
          //print_r($summaryData);
        var_dump($review->getData());
         }


}
4
  • not working unfortunately
    – yavonz15
    Commented Jul 21, 2016 at 10:12
  • @yavonz15 update the code try it Commented Jul 21, 2016 at 10:19
  • it does not work again
    – yavonz15
    Commented Jul 21, 2016 at 10:31
  • @yavonz15 update the code now tested too.. Commented Jul 21, 2016 at 10:47
0

Call a phtml file in cms page and put below code in this file:

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

foreach($_reviews as $review){
// load the product for the corresponding review if You need to display product information
$product = Mage::getModel('catalog/product')->load($review->getData('entity_pk_value'));
$j=0;
$cumulative = 0;
foreach( $review->getRatingVotes() as $vote ) {
$cumulative +=$vote->getPercent();
$j++;
}
$finalPercentage = 0;
if ($cumulative != 0){
$finalPercentage = ($cumulative/$j);
}
}//close the foreach
?>

Please let me know if you have any problem.

0

Complete code

 <?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>

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.