在 Magento 产品页面中查看

Review in Magento product page

我正在尝试让评论提交框显示在产品页面中,并在其下方显示最新评论。

所有教程都说的一样,但它行不通。有什么想法吗?

catalog.xml - 在此代码段中,您可以看到我包含了对评论的引用

 <catalog_product_view translate="label">



        <label>Catalog Product View (Any)</label>
        <!-- Mage_Catalog -->




        <reference name="root">


            <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
        </reference>
        <reference name="head">
            <action method="addJs"><script>varien/product.js</script></action>
            <action method="addJs"><script>varien/configurable.js</script></action>

            <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
            <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
            <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
        </reference>
        <reference name="content">

             <block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"/>

            <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
                <!--
                <action method="addReviewSummaryTemplate"><type>default</type><template>review/helper/summary.phtml</template></action>
                <action method="addReviewSummaryTemplate"><type>short</type><template>review/helper/summary_short.phtml</template></action>
                <action method="addReviewSummaryTemplate"><type>...</type><template>...</template></action>
                -->
                <block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
                <block type="core/text_list" name="alert.urls" as="alert_urls" translate="label">
                    <label>Alert Urls</label>
                </block>

然后在 catalog/product/view.phtml 我希望它出现的地方调用它:

   <?php echo $this->getChildHtml('reviews') ?>

在 catalog/product/view.phtml 中试试这个:

<div>
    <?php echo $this->getLayout()->createBlock('review/product_view_list')->setTemplate('review/product/view/list.phtml')->toHtml() ?>
</div>        
<div>   
    <?php echo $this->getLayout()->createBlock('review/form')->setBlockId('product.review.form')->toHtml() ?>
</div>

如果您想在产品 view.phtml 模板中显示评论,您需要将评论列表添加为适当块的子项。应该是catalog/product_view...(不是内容)。所以在你的例子中:

    <reference name="content">
        <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
            <block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"/>
            <block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>

那么<?php echo $this->getChildHtml('reviews') ?>就可以了。