【问题标题】:Magento - pull one single customer reviewMagento - 提取一个客户评论
【发布时间】:2011-05-18 09:50:46
【问题描述】:

我一直在尝试将一条客户评论拉到产品页面上。

我没有代码可以显示,因为老实说我不确定从哪里开始,也找不到任何关于它的在线提及。

有人有什么想法吗?

【问题讨论】:

    标签: php magento


    【解决方案1】:

    我之前写了一篇关于将所有评论元素带到产品页面的教程,因此您可以按照本教程进行操作:http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/product-reviews-on-product-view-page.php

    您所要做的就是重命名列表块并以相同的方式将其显示出来。然后只需修改循环,以您认为合适的任何方式显示评论。例如。限制为特定数量或仅回应特定用户的评论。

    编辑:

    获取最新评论非常简单,因为评论按日期顺序排列。

    转到 评论 > 产品 > list.phtml

    用以下代码替换该文件中的代码:

    <?php $_items = $this->getReviewsCollection()->getItems();?>
    <div class="box-collateral box-reviews" id="customer-reviews">
    <?php if (count($_items)):?>
        <h2><?php echo $this->__('Customer Reviews') ?></h2>
        <?php echo $this->getChildHtml('toolbar') ?>
        <dl>
        <?php $r_count = 0; ?>
        <?php foreach ($_items as $_review):?>
        <?php if ($r_count == 0) { ?>
            <dt>
                <a href="<?php echo $this->getReviewUrl($_review->getId()) ?>"><?php echo $this->htmlEscape($_review->getTitle()) ?></a> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
            </dt>
            <dd>
                <?php $_votes = $_review->getRatingVotes(); ?>
                <?php if (count($_votes)): ?>
                <table class="ratings-table">
                    <col width="1" />
                    <col />
                    <tbody>
                        <?php foreach ($_votes as $_vote): ?>
                        <tr>
                            <th><?php echo $this->escapeHtml($_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; ?>
                <?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
                <small class="date"><?php echo $this->__('(Posted on %s)',       $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
            </dd>
            <?php } ?>
            <?php $r_count++; ?>
        <?php endforeach; ?>
    
        </dl>
        <?php echo $this->getChildHtml('toolbar') ?>
    <?php endif;?>
    <?php echo $this->getChildHtml('review_form') ?>
    </div>
    

    我已经简单地将一个交互器放入循环 $r_count 并在 foreach 中进行检查,以防止它在下一次循环迭代中继续进行。

    【讨论】:

    • 再次感谢您的支持!,我目前在我的产品页面上拥有完整的评论系统,如果您能举例说明如何根据该页面产品提取最新评论。我将不胜感激
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    相关资源
    最近更新 更多