Magento产品评级显示单一评论的夏季

时间:2015-05-29 07:52:15

标签: php magento

我使用5个评级选项进行产品评审 它显示如下。

enter image description here

但我想显示该评论的总分。
一个分数,显示该分数的总分5的平均分数。

(我不想显示所有评论的平均值,只显示每次评论的平均值)

带有审核摘要代码的新代码:

<?php $reviews = Mage::getModel('review/review') ->getResourceCollection() ->addStoreFilter(Mage::app()->getStore()->getId())  ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) ->setDateOrder() ->addRateVotes();
$avg = 0; $totalrv = 0; $totalrvper =0; $ratings = array();
if (count($reviews) > 0) { foreach ($reviews->getItems() as $review) { foreach( $review->getRatingVotes() as $vote ) { $totalrv = $totalrv +$vote->getValue(); $totalrvper = $totalrvper + $vote->getPercent(); }
} $totalrv= ($totalrv/3)/4; $totalrvper = ($totalrvper/3)/4; $avgrate = round($totalrv, 1); } ?>

        <div class="summaryrating">
            <div class="categoryratings-header" style="display: none;">
                <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
            </div>
            <span class="reviewratingstars">            
                <div class="rating-box" style="padding-bottom: 34px;">
                    <div style="width:<?php echo $totalrvper; ?>%;" class="rating"></div>
                </div>
            </span>
            <span class="showcategoryratings" id="showcategoryratings-header">
                <span class="showcategoryratings-text" title="Bekijk de beoordelingen per categorie">Per categorie</span>
            </span>
        </div>

这是我的详细信息

    <?php $_votes = $this->getRatingVotes($_review->getId());?>
    <?php if (count($_votes)): ?>
    <table class="ratings-table">
        <col width="1" />
        <col />
        <tbody>
            <?php foreach ($_votes as $_vote): ?>
            <tr>
                <th><?php echo $_vote->getRatingCode() ?></th>
                <td>
                    <div class="rating-box">
                        <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
                    </div>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <?php endif; ?>

我该如何显示?

编辑显示单一审核摘要:

    <div class="ratingstars">
            <h4 class="title-beoordeling">Beoordeling</h4>
            <ul class="ratingbox">
            <?php foreach ($this->getRating() as $_rating): ?>
                <?php if($_rating->getPercent()): ?>
                     <li>
                        <span class="ratingcategoryname"><?php echo $this->__($_rating->getRatingCode()) ?></span>
                        <span class="reviewratingstars">
                            <div class="rating-score sum">
                                <div class="score-rating" style="width:<?php echo ceil($_rating->getPercent()) ?>%;"></div>
                            </div>
                        </span>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>

            <?php foreach ($_votes as $_vote): ?>
        <?php $summary += $_vote->getPercent(); ?>
        <?php $total++ ?>
            <?php endforeach; ?>
                     <li class="averagerating">
                        <span class="ratingcategoryname">Gemiddelde beoordeling</span>
                        <span class="reviewratingstars">
                            <div class="rating-score sum">
                                <div class="score-rating" style="width:<?php echo $summary/$total ?>%;"></div>
                            </div>
                        </span>
                   </li>
            </ul>
    </div>

2 个答案:

答案 0 :(得分:1)

    <?php $reviews = Mage::getModel('review/review') ->getResourceCollection() ->addStoreFilter(Mage::app()->getStore()->getId()) ->addEntityFilter('product', Mage::registry('current_product')->getId()) ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) ->setDateOrder() ->addRateVotes();
$avg = 0; $avgper = 0; $totalrv = 0; $totalrvper =0; $ratings = array(); $count = 0;
if (count($reviews) > 0) { foreach ($reviews->getItems() as $review) { foreach( $review->getRatingVotes() as $vote ) { $totalrv = $totalrv +$vote->getValue(); $count++; $totalrvper = $totalrvper + $vote->getPercent(); }
} $avg= $totalrv/count($reviews); $avgper = round($totalrvper/$count ,1);} ?>
        <div class="summaryrating">
            <div class="categoryratings-header" style="display: none;">
                <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
            </div>
            <span class="reviewratingstars">

                <div class="rating-box" style="padding-bottom: 34px;">
                    <div style="width:<?php echo $avgper; ?>%;" class="rating"></div>
                </div>
            </span>
            <span class="showcategoryratings" id="showcategoryratings-header">
                <span class="showcategoryratings-text" title="Bekijk de beoordelingen per categorie">Per categorie</span>
            </span>
        </div>

答案 1 :(得分:0)

<?php
$reviews = Mage::getModel('review/review')->getResourceCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addEntityFilter('product', Mage::registry('current_product')->getId())->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)->setDateOrder()->addRateVotes();
$avgper = 0;
$totalrvper = 0;
$ratings = array();
$count = 0;
$totalcount = 0;
if (count($reviews) > 0) {
foreach ($reviews->getItems() as $review) {
    foreach ($review->getRatingVotes() as $vote) {
        $totalcount++;
        $totalrvper = $totalrvper + $vote->getPercent();
        $ratings[$vote->getCode()]["count"] = $ratings[$vote->getCode()]["count"] + 1;
        $ratings[$vote->getCode()]["avg"] = $ratings[$vote->getCode()]["avg"] + $vote->getPercent();
    }
}
$avgper = round($totalrvper / $totalcount, 1);}?>
<div class="summaryrating">
<div class="categoryratings-header" style="display: none;">
<?php echo $this->getReviewsSummaryHtml($_product, false, true) ?>
</div>
<span class="reviewratingstars">

    <div class="rating-box" style="padding-bottom: 34px;">
        <div style="width:<?php echo $avgper; ?>%;" class="rating"></div>
    </div>
</span>
<span class="showcategoryratings" id="showcategoryratings-header">
    <span class="showcategoryratings-text" title="Bekijk de beoordelingen per categorie">Per categorie</span>
</span>
<span class="reviewperratingstars">
<?php foreach($ratings as $code => $rating) : ?>
    <div class="rating-box" style="padding-bottom: 34px;">
        <span class="label"><?php echo $code ?></span>
        <span style="width:<?php echo round($rating["avg"]/$rating["count"],1); ?>%;" class="rating"></span>
    </div>
<?php endforeach; ?>
</span>

`