Magento Forum

Same product in different categories with different layout (solved)
 
aarondong
Jr. Member
 
Total Posts:  7
Joined:  2013-01-28
 

I have a product in two different categories.  I want the product layout in those categories to be different. So I searched online. The only result I could find is this link http://stackoverflow.com/questions/9006734/magento-product-specfic-designs-through-custom-layout-update

I followed the second answer from the link. So I modified the ‘/app/code/core/Mage/Catalog/controllers/ProductController.php’ in _initProductLayout method from this

protected function _initProductLayout($product)
    
{
        Mage
::helper('catalog/product_view')->initProductLayout($product$this);
        return 
$this;
    
}

to this

protected function _initProductLayout($product)
    
{
        $update
->addHandle('CATEGORY_'.$product->getCategoryId());
        
Mage::helper('catalog/product_view')->initProductLayout($product$this);
        return 
$this;
    
}

Then, In the product design section I placed those code to update the layout by using view-parts.phtml. So it should be only take effect in CATEGORY_63

<CATEGORY_63>
    <
reference name="root">
        <
action method="setTemplate"><template>catalog/product/view-parts.phtml</template></action>
    </
reference>
</
CATEGORY_63>

But in category 63 the layout has no change it still using default view.phtml. I tried delete the <CATEGORY_63> code, then it works. That means the code should be fine with the conditional code CATEGORY_63.
I want it only change the layout in category 63 not other category. Please help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
aarondong
Jr. Member
 
Total Posts:  7
Joined:  2013-01-28
 

Ok. I just find the solution myself. And much simple than I was asking.

You don’t have to modify the ProductController.php.

You just need to update the Custom Layout Update in the category you want the product use different layout with following code.

<reference name=\"product_list\">
    <
action method=\"setTemplate\">
        <
template>catalog/product/list-parts.phtml</template>
    </
action>
</
reference>

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

Then set Apply To Products to yes. To apply the modified view.phtml to the product layout. Very very simple!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top