Reputation: 3894
In theory how should I code this or implement a solution to my problem?
Let say I have a 3 various design for product page.
I think they all just share one template (app/design/frontend/default/skinName/template/product/view.phtml) but I want to do 3 variation for each of them. Each of product variation also have different attributes. I'm using Magento 1.6.
Please advice where do I start.
Thank You!
Upvotes: 0
Views: 440
Reputation: 14182
Are the three different product variations separate product types by chance (e.g. configurable, simple and downloadable)? If so, you could set a different template using a layout update declaration in your themes layout/local.xml file:
<layout>
<PRODUCT_TYPE_configurable>
<reference name="product.info">
<action method="setTemplate">
<template>my/catalog/product/view_configurable.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_configurable>
<PRODUCT_TYPE_simple>
<reference name="product.info">
<action method="setTemplate">
<template>my/catalog/product/view_simple.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_simple>
<!-- etc... -->
</layout>
You could also use the custom layout updates property of products to specify the template to use via layout XML. In that case simply omit the layout handle from the code above.
If your product variations can't be distinguished by product type, and you don't want to add custom layout XML to every product, you will indeed have to create a product attribute that specifies which type the product belongs to. Make it invisible on the frontend if you don't want customers to see it.
Then, create an event observer for the controller_action_layout_render_before_catalog_product_view
event.
In the observer method, get the product.info block and set the template you want.
public function controllerActionLayoutRenderBeforeCatalogProductView(Varien_Event_Observer $observer)
{
$block = Mage::app()->getLayout()->getBlock('product.info');
switch ($observer->getProduct()->getYourAttribute())
{
case 'Special Products':
$block->setTemplate('my/catalog/product/view_special.phtml');
break;
case 'Regular Products':
$block->setTemplate('my/catalog/product/view_regular.phtml');
break;
case 'Other Products':
$block->setTemplate('my/catalog/product/view_other.phtml');
break;
}
}
Another option - even though more conflict prone - would be to rewrite the catalog/product_view
block, overload the _beforeToHtml()
method and specify the template to use there. I'll won't go into more detail here because I think the previous options are better.
So, depending on the type of approach you take, there are many possibilities (these aren't all).
Upvotes: 3
Reputation: 931
you have to create different attribute for them like as for special product, create attribute special type "yes/no" and you will select this option when you will add product each time. and finally in view.phtml you have to check this product is special or not. and use you condition and implement your own design here. hope this will help you. thanks
Upvotes: 0