2011-08-04 98 views
2

在我的Magento店的顧客正在審查我的產品在3個類別(即價格)。但是,當我打印這些評級只顯示摘要,而不是這3個基本分類(見代碼)。Magento的評論都出現了總結,評價,而不是評價項在PHP

<?php 
    //from http://www.exploremagento.com/magento/run-magento-code-outside-of-magento.php 
    require_once '../app/Mage.php'; 
    umask(0); 
    Mage::app('default'); 

    $review = Mage::getModel('review/review'); 
$collection = $review->getProductCollection(); 
$collection 
     ->addAttributeToSelect('*') 
     ->getSelect() 
       ->limit(5) 
       ->order('rand()'); 
$review->appendSummary($collection); 

foreach($collection as $product) { 
     //var_dump($product->debug()); 
} 

/* To get (what I assume is) 'star' rating. */ 
$ratingSummary = $product->getRatingSummary(); 
$starRating = $ratingSummary['rating_summary']; 
echo $starRating . "<br/>"; 
?> 

我怎樣才能得到全部的收視率,而不是總結?

+0

你解決這個問題? – Anthony

回答

-1

我創建了一個幫助對象這個功能,只是爲了顯示產品平均等級(也3類)簡單的HTML。希望你覺得它有幫助。

public function getRatingHtml($product_id) { 

     $store_id = Mage::app()->getStore()->getId(); 

     $query = " 
     SELECT 
      ROUND(AVG(`percent_approved`)) as `rating` 
     FROM 
      `rating_option_vote_aggregated` 
     WHERE 
      `entity_pk_value` = {$product_id} 
      AND 
      `store_id` = {$store_id}"; 

     $read = Mage::getSingleton('core/resource')->getConnection('core_read'); 
     $rating = $read->query($query)->fetch(); 
     $html = " 
     <a href=\"/review/product/list/id/{$product_id}/\" class=\"rating-box-link\"> 
     <span class=\"rating-box\"> 
     <span class=\"rating\" style=\"width: {$rating['rating']}%;\"></span> 
     </span> 
     </a>"; 
     return $html; 
    }