Magento 1.9 – Change Page Layout for Products Under Specific Category

designlayoutmagento-1.9rwd-theme

I am trying to set 2columns-right.phtml layout for products under specific category while the default is 1column.phtml.(Please note i don't want to change Category page layout but layouts of products under that category)

I tried Admin >Manage categories >Select Category >Custom design >Change "Apply to Products" to yes and in "Custom Layout Updates" entered

<reference name="product.info">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</reference>

Didn't work

Then i went to rwd/default/layout/catalog.xml and added after

<!--
    Product view
    -->

Entered

<CATEGORY_3>
<reference name="product.info">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    </reference>
    </CATEGORY_3>

But even this didn't work, It would be of great help any ideas on this. Magento CE Version 1.9.1

Best Answer

Create a small module

Your config.xml should looks like

app/code/codePool/Package/Extension/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Package_Extension>
            <version>0.1.0</version>
        </Package_Extension>
    </modules>
    <global>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <categoryhandle>
                        <class>Package_Extension_Model_Observer</class>
                        <method>cateHandle</method>
                    </categoryhandle>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </global>
</config>

Your observer should looks like

app/code/codePool/Package/Extension/Model/Observer.php

<?php
class Package_Extension_Model_Observer
{

    public function cateHandle(Varien_Event_Observer $observer)
    {
        $product = Mage::registry('current_product');

        /**
         * Return if it is not product page
         */
        if (!($product instanceof Mage_Catalog_Model_Product)) {
            return;
        }
        $category= 3;
        $categories=$product->getCategoryIds();
        if(in_array($category, $categories)){
            $update = $observer->getEvent()->getLayout()->getUpdate();
            $update->addHandle('PRODUCT_CATEGORY_'.$category);
        }

    }
}

And in your themes local.xml add below code or as you mention rwd/default/layout/catalog.xml add below code

<PRODUCT_CATEGORY_3>
    <reference name="root">
      <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    </reference>
</PRODUCT_CATEGORY_3>