We devided all the products into two categories:

  • "Main products"
  • "Accessories"

All listed products from the category "Main products" are opened with our custom template: catalog/product/view_main_producs.phtml

Here it comes the tricky part :)

All products from the category "Accessories" needs to be opened with different custom template catalog/product/view_accessories.phtml, because the products from this category have different attributes.

In some way we managed (partly) to acchive this with the following lines of code:

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

We inserted the above code into "Accessories" category Custom Design -> Custom Layout Update

With the above code we managed to open products from category "Accessories" into on our custom view_accessories.phtml template!

Here is what is the problem. Above code only works if a person came to our web site through the links on our web site.

Now we have two issues:

  1. If person come to our web site and search for accessories products (search toolbar), the product will not be opened in view_accessories.phtml template!
  2. If person click on the products while searching for it on google, bing (SEO search), the product will not be opend in "view_accessories.phtml"!

Our question is: how to achieve for all products from "accessories" category to be opened in "view_acccessories.phtml" - no matter how come the person access the link?

Thanks in advenced :)

1 Answer 1


Try following way:


<?xml version="1.0"?>


<?xml version="1.0"?>



class SR_MagentoCommunity_Model_Observer

    public function controllerActionLayoutRenderBeforeCatalogProductView(Varien_Event_Observer $observer)
        $layout = Mage::getSingleton('core/layout');
        $request = Mage::app()->getRequest();
        $productId  = (int) $request->getParam('id');
        /** @var Mage_Catalog_Model_Product $product */
        $product = Mage::getModel('catalog/product')
        $categoryIds = $product->getCategoryIds();
        // suppose 14 is your category id
        if (in_array(14, $categoryIds)) {
  • Dear Sohel Rana, your are my Idol :) This just works perfect. Thank you 1000 times.
    – user15151
    Commented Feb 3, 2019 at 14:42
  • 1
    Great to know. Happy to help always.
    – Sohel Rana
    Commented Feb 3, 2019 at 15:22
  • hi Sohel Rana, I encountered to some issue regarding similar functionality. Would you please be so kind to look at the question at the link: magento.stackexchange.com/questions/291847/…
    – user15151
    Commented Oct 8, 2019 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.