【问题标题】:looking to show product reviews in sidebar on product page magento希望在产品页面 magento 的侧边栏中显示产品评论
【发布时间】:2011-06-27 12:31:14
【问题描述】:

我希望在 magento 产品页面的侧边栏中显示该产品的最新评论(可能是 3 或 4 条)。

显示评论的前 10 或 15 个单词、星号栏和评论页面的链接以查看所有评论..

非常感谢任何建议或指示,

谢谢,

强尼

【问题讨论】:

    标签: magento sidebar review


    【解决方案1】:

    正如 ElGabby 所说,创建一个扩展是可行的方法。

    但您可以通过编辑当前布局来做到这一点。

    转到 /app/design/frontend/default/[your theme]/layout/ 或 /app/design/frontend/base/[your theme]/layout/ 中的文件 catalog.xml

    找到该部分:

    <catalog_product_view>
    

    在那里你很可能有一个类似的部分:

    <reference name="right">
    

    在该部分添加:

    <block type="review/product_view" name="right.rewiev" template="review/rightbar.phtml" />
    

    我的示例中的部分如下所示:

    <reference name="right">
            <block type="review/product_view" name="right.rewiev" template="review/rightbar.phtml" />
            <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
        </reference>
    

    保存文件并在以下位置创建一个新文件: /app/design/frontend/default/[你的主题]/design/review/rightbar.phtml

    该文件的内容类似于:

    <?php $collection = $this->getReviewsCollection(); ?>
    <?php if(count($collection) > 0):?>
    <?php foreach ($collection as $rating):?>
    
        <?php echo $rating->title //title of the rewiev?>
    
        <?php echo $rating->detail //content of the rewiev?>
        <?php echo $rating->created_at //data rewiev is created?>
    <?php endforeach;?>
    <?php endif;?>
    

    【讨论】:

      【解决方案2】:
      • 我会创建一个扩展。
      • 使用 layout.xml 将应该扩展核心/模板块的块放置在产品页面的左侧/右侧边栏中
      • 在该块类中,您应该有一些方法可以从数据库中检索您希望显示的评论。所以比如说你需要一个方法 getReviews()
      • 在模板中调用 $this->getReviews() 并迭代结果并根据需要显示评论。星号栏可能有点麻烦,但是如果您查看使用它们的其他模板文件,您应该能够了解它的要点:)

      HTH :)

      【讨论】: