I found an observer and modified it a bit which should overwrite the standard product layout. This works, however, if I have cache enabled it keeps loading my page from cache.
What I actually need is, that as soon as the GET parameter "template" is set the page should be cached so I don't have any problems.
Normal product ie: http://www.website.com/product.html
Product in popup: http://www.website.com/product.html?template=popup
With cached disabled it works, enabled it doesn't. Hope somebody can help me.
Here's the observer.php
class Unleaded_ForceLayout_Model_Observer
{
public function changeLayoutEvent($observer)
{
$action = $observer->getEvent()->getAction();
$layout = $observer->getEvent()->getLayout();
if(($action->getRequest()->getControllerName() == 'product' && $action->getRequest()->getActionName() == 'view'))
{
$template = $action->getRequest()->template;
if (isset($template) && $template != '')
{
$cache = Mage::app()->getCacheInstance();
$cache->banUse('full_page');
$update = $layout->getUpdate();
$update->load($template);
$layout->generateXml();
}
}
}
}
And the XML
<?xml version="1.0"?>
<layout version="0.1.0">
<default></default>
<popup translate="label">
<label>Catalog Product View Popup</label>
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate">
<template>page/popup.phtml</template>
</action>
</reference>
<reference name="content">
<remove name="catalog.product.related"/>
<remove name="product.attributes"/>
<remove name="product.info.upsell"/>
<remove name="product.description"/>
<remove name="product.info.additional"/>
<remove name="product.description"/>
<remove name="product.info.container1"/>
<remove name="product.info.container2"/>
</reference>
</popup>
</layout>
Best Answer
So the code example below was working for me with the event "controller_action_layout_load_before" as I could not see this noted in your question. It would work with and without cache enabled and on both rendering the regular template and the new popup template. Please updated me if this is not the correct event or if this is not one that you can use and I will try changing my code.
/app/etc/modules/Manners_Test.xml
/app/code/local/Manners/Test/etc/config.xml
/app/design/frontend/base/default/layout/manners_test.xml
/app/code/local/Manners/Test/Model/Observer.php