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.
- Special Products / attributes: [Name:, Blurb:, Price:, Product Image:, Description:, ]
- Regular Products / attributes: [Name:, Product Image:, Description:, ]
- Other Products / attributes: [Name:, Product Image:, Description:, Links:, ]
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!
Option 1: layout XML by product type
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:
Option 2: custom layout updates
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.
Option 3: event observer
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_viewevent.In the observer method, get the product.info block and set the template you want.
Option 4: block rewrite
Another option – even though more conflict prone – would be to rewrite the
catalog/product_viewblock, 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).