How to add review tab on product view page

2020-03-26 23:27发布

问题:

I am a beginner in Magento. I want to add a Review Tab in product view page. Can anyone help me how to do this?

I tried following approach:

<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml">
                    <!--action method="addTab" translate="title" module="catalog"><alias>additional</alias><title>General Info</title><block>catalog/product_view_attributes</block><template>catalog/product/view/attributes.phtml</template></action-->
                    <action method="addTab" translate="title" module="catalog"><alias>description</alias><title>Description</title><block>catalog/product_view_description</block><template>catalog/product/view/description.phtml</template></action>
                    <action method="addTab" translate="title" module="catalog"><alias>upsell</alias><title>Upsell</title><block>catalog/product_list_upsell</block><template>catalog/product/list/upsell.phtml</template></action>
                    <action method="addTab" translate="title" module="catalog"><alias>review</alias><title>Review</title><block>review/product_view_list</block><template>review/product/view/list.phtml</template></action>
                    <action method="addTab" translate="title" module="catalog"><alias>additional</alias><title>Additional Information</title><block>catalog/product_view_attributes</block><template>catalog/product/view/attributes.phtml</template></action>

    </block>

Then using echo $this->getChildHtml('info_tabs'); in view.phtml.

Only description, review and additional information are visible. What may be the problem? Thanks

回答1:

Here is my answer from this duplicate question

This is how I handled this situation in one of my projcets:

Add tab with reviews,

<block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
    <action method="addTab" translate="title" module="catalog"><alias>tab_review_list</alias><title>Product Reviews</title><block>review/product_view_list</block><template>catalog/product/view/tabs/reviews.phtml</template></action>
</block>

Now, the review form is handled by the different type of block which normally is a sub-block of review page. There is no way to make nested block with addTab action but you can use <reference> handler after creating review block in tabs like this:

<reference name="tab_review_list">
  <block type="review/form" name="tab_review_form" as="review_form" template="catalog/product/view/tabs/review_form.phtml" />
</reference>

name in <reference> handler must be equal to what is in <alias> in addTab action.

And in catalog/product/view/tabs/reviews.phtml you just use,

echo $this->getChildHtml('review_form');

You can use <reference> handler to add more block to review list and review form.

Of course, you have to create files for review list and review form in the paths entered in template argument, so in this case you would need to create catalog/product/view/tabs/reviews.phtml and catalog/product/view/tabs/review_form.phtml. You can change review form template to the default one review/form.phtml If you do not need change the code there or you will be using it only in that tab but review list might need more changes in html structure so it is good idea to create separate file for it and use parts of the default code as needed.



标签: magento