Micha
Micha

Reputation: 11

Add custom tab to Magento product detail pages depending on category

In our Magento store we offer two kinds of products, each with their own root categories. I want to add CMS Static Blocks as custom tabs on product detail pages that are dependent on which category the product is under.

I know how to create tabs in the view.phtml template, but how can I make it so that:

I think it is possible with XML layout updates to remove and append tabs, but how do I append the blocks to the layout?

Upvotes: 1

Views: 1841

Answers (1)

fantasticrice
fantasticrice

Reputation: 1621

Overview

If I am understanding your question correctly, you want to add a custom tab on the product detail page when viewing the product under your two special categories (category1 and category2).

The tabs on the product detail page are of type catalog/product_view_tabs which normally maps to the class Mage_Catalog_Block_Product_View_Tabs. This block does provide a way to add new tabs through its addTab() method, but it seems that this method assumes a template will be used, which unfortunately prevents using a CMS Static Block with this method.

A Possible Solution

If you are able to put your content from the two static blocks into two template files instead, you could do this using layout XML updates on the categories themselves. I will outline the process you would use in this scenario:

  1. Navigate to Catalog > Categories > Manage Categories in Magento Admin and click on category1 in the tree.
  2. Open the Custom Design tab.
  3. Set “Apply To Products” to Yes.
  4. Now add the layout update for that category’s products that should have the custom tab under “Custom Layout Update”:

<reference name="content">
    <reference name="product.info.tabs">
        <action method="addTab" translate="title">
            <alias>block1</alias>
            <title>Block 1</title>
            <block>core/template</block>
            <template>catalog/product/view/block1.phtml</template>
        </action>
    </reference>
</reference>

It should look something like this: enter image description here

Then just repeat the same steps for category2. The key to this solution working is to get your two template files block1.phtml and block2.phtml into the path: app/design/frontend/base/default/template/catalog/product/view/.

Upvotes: 1

Related Questions