Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento product view template based on category

Tags:

magento

We are working on a Magento webshop which has two categories.

We would like to use the default product view template for category one, and a custom product view template for category two.

Is this possible and how we can achieve this?

* EDIT - SOLUTION *

For anyone who is curious about this. The solution was a lot easier than I thought.

I only had to place this piece of code in the custom layout update section of the relevant category and i had to set the option 'Apply to products' to yes!

<reference name="product.info">
    <action method="setTemplate"> <template>catalog/product/view-recipe.phtml</template></action>
</reference> 

* EDIT * I have tried adding this code to the catalog.xml.

<CATEGORY_5>
    <reference name="product.info">
        <action method="setTemplate"><template>catalog/product/view-recipe.phtml</template></action>
    </reference>
</CATEGORY_5>

* EDIT * I have tried adding this code to the catalog.xml:

<CATEGORY_5>
    <reference name="product.info">
        <action method="setTemplate"><template>catalog/product/view-recipe.phtml</template></action>
    </reference>
</CATEGORY_5>

And this code to the Custom Layout Update section:

    <reference name="product.info">
        <action method="setTemplate"><template>catalog/product/view-recipe.phtml</template></action>
    </reference>

I installed the patch but unfortunately still no results.

like image 775
Michael Avatar asked Mar 22 '12 09:03

Michael


1 Answers

Did you mean category catalog list? Then you can try "Custom Layout Update".

  • Catalog -> Manage Categories
  • Select custom layout from "Page Layout"
  • Add the following in "Custom Layout Update"
<reference name="product_list">
<action method="setTemplate">
    <template>catalog/product/custom-theme.phtml</template>
</action>
</reference>

Of course, you should create first custom layout, you can take reference from the base list.phtml

* EDIT * If you want customize specific products/categories then you can use custom layout handle. Take consider the following links.

  • Advanced Layout Updates
  • Creating custom layout handles

* EDIT * First you should modify CategoryController.php viewAction() method from /app/code/core/Mage/Catalog/Controllers folder ( as specified in Inchoo sample ).

Then, you should do something like that :

<CATEGORY_20>
<reference name="product.info">
            <action method="setTemplate"><template>catalog/product/custom-theme.phtml</template></action>
    </reference>
</CATEGORY_20>

* EDIT * Magento has a bug about Custom Layout Update which is issue id 7625. They specified fixed in next release over Bug Track but still has a problem. So, Ingo Weseloh made a patch which you can find the following link.

Exanto Reclayup 7625

* EDIT *

Michael, could you please try this ( it's Alan Storm's sugestion )

<CATEGORY_20>
<reference name="product.info">
  <action method="setTemplate"><template>catalog/product/custom-theme.phtml</template></action>
  <action method="setIsHandle"><applied>1</applied></action>
</reference>

like image 180
Oğuz Çelikdemir Avatar answered Sep 18 '22 17:09

Oğuz Çelikdemir