2

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

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

4

1 回答 1

-1

我在帮助对象中创建了这个函数,只是为了显示简单的 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;
    }
于 2012-03-20T17:30:31.570 回答