2
votes

Let's say I have two categegories, A and B.

I set A to use 'layout_a' on Catalog -> Catalog Categories -> Click a category -> click custom design tab

I set B to use 'layout_b' on Catalog -> Catalog Categories -> Click a category -> click custom design tab

When I visit category A and B, theydisplays products using their own layout that I set on the admin panel. When I click an item on the product listing page, product view page does not use custom design.

How do I enforce product view page to use its category's custom design?

4
Think you mean "I set B to use 'layout_b' on ..." :)Jonathan Day

4 Answers

6
votes

In the current versions of Magento there is another way to do this without changing core code. Lets say you have a custom template for the product display of a category. In Admin go to Catalog->Categories->Manage Categories and select the category you want to apply the modified product template to. Change "Apply to Products" to Yes and put the following in the Custom Layout Update;

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

Where NEW_VIEW is the name of the new template you want to use. If you have sub-categories you may need to have their "Use Parent Category Settings" set to Yes in order for it to float through.

4
votes

I found the answer by myself.

  1. Open product controller located in /app/code/Mage/Catalog/controllers/ProductController.php

  2. add the following code into _initProductLayout method

    $update->addHandle('CATEGORY_'.$product->getCategoryId());

  3. Open catalog layout xml located in /app/design/frontend/default/default/layout/catalog.xml

  4. add

<CATEGORY_"your category id">
    <reference name="root">
  <action method="setTemplate"><template>yourtemplate here</template></action>
    </reference>
</CATEGORY_"your category id">
0
votes

You can apply the Custom Design updates on the product Catalog>Manage Products>Design and then apply as per the Categories

Does that achieve what you need?

0
votes

Create an attribute with dropdown type and name attribute code 'which_category'. On the options tab fill in 'category_a' and 'category_b'

Create two files in /app/design/frontend/default/YOURTEMP/template/catalog/product/

lets say: view_cat_a.phtml and view_cat_b.phtml

You can design your specific category product view page based on view.phtml.

Change view.phtml to:

<?php 
$_helper = $this->helper('catalog/output'); 
$_product = $this->getProduct();
    if ( $_product->getAttributeText('which_category') == category_a) {
        include('view_cat_a.phtml');
    } else {
        include('view_cat_b.phtml');
    }

When you create a product you can choose the category on the attribute (define them in attribute_set)