Monday, August 20, 2012

Magento:: how to get Review/Rating information

>> Get the review collection :

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

>> Get the rating summary of a product:


    $summaryData  =  Mage::getModel('review/review_summary')
          ->setStoreId($storeId)
          ->load($_product->getId());
  
    foreach($summaryData as $s){
        $percentage = $s[rating_summary];
        $rev_count= $s[reviews_count];
        break;
    }

>> Get the rating collection :


    $rating_collection = Mage::getModel('rating/rating')->getEntitySummary($_review->getEntityPkValue(),true);
    $rating_count = $rating_collection->getData('count');
    if (!empty($rating_count)) {
        $rating_sum = $rating_collection->getData('sum') / $rating_count;
    }


1 comment: