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

この関数をヘルパー オブジェクトで作成しました。これは、平均的な製品評価 (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;
    }
于 2012-03-20T17:30:31.570 に答える