Magento评论显示汇总评级而不是php中的评级项目

时间:2011-08-04 21:09:23

标签: php magento rating review

在我的Magento商店,客户正在以3个类别(即价格)审核我的产品。但是当我打印这些评级时,它只显示摘要而不是这3个类别(见代码)。

<?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/>"; 
?> 

如何获得所有评分而非摘要?

1 个答案:

答案 0 :(得分:-1)

我在helper对象中创建了这个函数,只是为了显示平均产品评级的简单html(也是3个类别)。希望你发现它有用。

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;
    }