How to display category custom design layout in product view page?

前端 未结 4 1440

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 se

相关标签:
4条回答
  • 2021-01-01 08:35

    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 讨论(0)
  • 2021-01-01 08:44

    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.

    0 讨论(0)
  • 2021-01-01 08:53

    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 讨论(0)
  • 2021-01-01 08:56

    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)

    0 讨论(0)
提交回复
热议问题