Magento 评论在 php 中显示摘要评级而不是评级项目

发布于 2024-11-28 00:28:29 字数 860 浏览 0 评论 0原文

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

我怎样才能获得所有评级而不是摘要?

In my Magento store customers are reviewing my products in 3 categories (i.e. price). But when I'm printing these ratings it only shows a summary instead of these 3 categeries(see code).

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

How can I get all the ratings instead of the summary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方。的韩爷 2024-12-05 00:28:29

我在辅助对象中创建了这个函数,只是为了显示平均产品评级的简单 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;
    }

I've created this function in helper object, just to display simple html for average product rating (also 3 categories). Hope you find it helpfull.

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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文