0
votes

In magento project, I have four categories and I have 2 template file for products

Like

1) catalog/product/view.phtml (original)

2) catalog/product/newview.phtml (new file)

Now I want to display product layout based on category

like category id 1 and 2, product display base on view.phtml

and category 3 and 4, product display based on newview.phtml

2

2 Answers

0
votes

You can set this on each product in the backend in the design tab set :

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

Else you can also perform this through an Observer to get all product from category X in one shot.

Create your own module observing the controller_action_layout_generate_blocks_after event with a function like this one :

public function generateBlocksAfter($event)
{                      
    $controller   = $event->getAction();
//limit to the product view page 
if($controller->getFullActionName() != 'catalog_product_view')
{
    return;
}
$layout       = $controller->getLayout();
$product_info = $layout->getBlock('product.info');
if(!$product_info)
{
     Mage::log('Could not find product.info block');
     return;
 }
$id = Mage::registry('current_product')->getId();
$prod = Mage::getModel('catalog/product')->load($id);
$category_ids = $prod->getCategoryIds();
if(in_array(3,$category_ids) || in_array(4,$category_ids))     
     $product_info->setTemplate('catalog/product/newview.phtml');
}
0
votes

use this code for display according to categories id in local.xml files

      <reference name="product_list">
          <action method="setTemplate"><name>catalog/product/list_new.phtml</name></action>
      </reference>
 </CATEGORY_5>