3

I want to have custom design only for all products which are under a one category. Assume you have category 'A' and it has products 'a','b','c'. I want only to show these 'a,b,c' products in a different structure (design). How to achieve this?

  • you mean for products that comes under a specific category? – Rajeev K Tomy Oct 16 '14 at 18:23
  • I need custom design for products that comes under a particular category – Sukeshini Oct 17 '14 at 4:26
  • did you try my solution ? – Rajeev K Tomy Oct 17 '14 at 5:07
  • The thing is your answer is not actually answering this particular question as I mentioned. But it is good to see how you solve your own problem. There is no offence in that. – Rajeev K Tomy Oct 17 '14 at 9:58
  • I don't totally avoid your answer. It's one of the proper way of doing this. If I couldn't find the way which I mentioned in my answer, I'll definitely follow yours. But my answer is the simplest thing that can be done at the moment. Thanks again for the responses. Finally got to know two solutions :) – Sukeshini Oct 17 '14 at 10:29
6

This might be the easiest solution possible. Create a new theme and only change the product view page structure in that theme. There's a configuration available in admin panel, which allows you to assign a theme against a product. See the image below.

enter image description here

Hope this would be useful for anyone searching for this.

  • This is not the "right" answer for your own question. Your question clearly demands that, you need a special look for products that comes UNDER A PARTICULAR CATEGORY. But this answer suits for a question that demands "I need custom product view for a specific product". Both cases are too different. :-) – Rajeev K Tomy Oct 17 '14 at 7:03
  • programmer_rkt :I edited the question. Only the second solution in your answer maps with what I expected. Thanks for pointing out the weak points :) – Sukeshini Oct 17 '14 at 9:56
6

Following solution is done by editing the custom layout update section of the relevant category. Edit yourTheme/template/catalog/product/view-recipe.phtml file to obtain the look you want for the products of the specific category.

For anyone who is curious about this. The solution was a lot easier than I thought.

I only had to place this piece of code in the custom layout update section of the relevant category and i had to set the option 'Apply to products' to yes!

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

source : https://stackoverflow.com/questions/9819903/magento-product-view-template-based-on-category

  • This is not an answer to this question. – Rajeev K Tomy Oct 17 '14 at 5:07
  • Can be the answer, the question is not really clear. – Lanks Oct 17 '14 at 6:32
  • first editing core codes is a big "NO NO". second your codes looks not clear, means where should it apply. When answer, do it in detail. do you get me friend :-) – Rajeev K Tomy Oct 17 '14 at 6:48
  • This code must be placed in "the custom layout update section of the relevant category" as precised in the post. The only file that should be edited is myTheme/template/catalog/product/view-recipe.phtml. If i didn't develop my answer it's because i give the link to the original post. – Lanks Oct 17 '14 at 6:55
  • Thanks for the answer and sorry if my question is not clear. But this is not what I expected – Sukeshini Oct 17 '14 at 6:59
5

Your question is not clear. However if you are looking to customize a particular category, then it is very easy to dot that. Magento generates a specific layout handle for each categories. It will name like CATEGORY_{ID}.

So suppose the category id is 22. then create local.xml layout file and put your custom design like this

File : app/design/frontend/<package>/<theme>/layout/local.xml

<layout>
    <CATEGORY_22>  
         <!-- custom design comes here -->
    </CATEGORY_22>
</layout>

However if you need custom design for products that comes under a particular category, then there is no easy way to do this as per my knowledge.

One work around is check whether a product belongs to a particular category through an observer. If yes, add a custom layout handle to the layout. Later use this custom layout handle in order to put your custom designs.

So create an observer like this. (Let me call this module as Test_Test)

File : app/code/local/Test/Test/etc/config.xml

<config>
    <frontend>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <category_product_controller_action_layout_load_before>
                        <class>test_test/observer</class>
                        <method>controllerActionLayoutLoadBefore</method>
                    </category_product_controller_action_layout_load_before>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </frontend>
    <global>
        <models>
            <test_test>
                <class>Test_Test_Model</class>
            </test_test>
        </models>
    </global>
</config>

The event we are observing here is ontroller_action_layout_load_before. This is a general event. So we it is important to do some pre checking before further proceeding. Observer somewhat looks like this.

File : app/code/local/Test/Test/Model/Observer.php

<?php

class Test_Test_Model_Observer
{
    public function controllerActionLayoutLoadBefore(Varien_Event_Observer $observer)
    {
        //replace this with your category id
        $categoyId = 12;

        $event = $observer->getEvent();

        //ensure product view page
        if ($event->getAction()->getFullActionName() == 'catalog_product_view') {
            $product = Mage::registry('current_product');

              //make sure product belongs to required categoy
            if (in_array($categoyId, $product->getCategoryIds())) {

                //adding custom layout handle
                $layout = $event->getLayout();
                $layout->getUpdate()->addHandle('special_category_product_view');
            }

        }

    }
}

Observer will add a custom layout handle special_category_product_view if the product that we viewing belongs to a particular category.Now in your layout XML file (you can associate one for this module and then use it. I recommend this. Or use local.xml), you can use this handle and specify your custom design there

Hope that will help

  • Thanks a lot. I didn't tryout your answer yet. But it's one of the possible ways to achieve what I want. And +1 – Sukeshini Oct 17 '14 at 6:58
0

Tried the solutions from here, nothing worked for me (magento 1.9.3.4). Found a much simpler solution:

create a fancy_name.phtml file in your_theme/default/template/page/ (from copy of 1column-product.phtml or something).

Edit fancy_name.phtml until it becomes really fancy.

Go to magento backend, go to your product, go to design -> Custom layout update. Paste the following code and save:

<reference name="root">
    <action method="setTemplate"><template>page/fancy_name.phtml</template></action>
</reference>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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