2

I am using one step checkout and shipping_method.phtml responsible for showing the shipping methods.so now i have 2 more modules which both have shipping_method.phtml each.so i need to show either shipping_method.phtml from Module A or Module B depending on the shipping country.

so i wanted to update handle called in that i will be updating the handle with module A or B depending on the condition statfication which just updates the setTemplate file either from A or B.

Please Help me how to achive this.

<a_onestepcheckout>
    <reference name="choose-shipping-method">
        <action method="setTemplate">
            <template>a/l/onestepcheckout/shipping_method.phtml</template>
        </action>
    </reference>
</a_onestepcheckout>

<b_onestepcheckout>
    <reference name="choose-shipping-method">
        <action method="setTemplate">
            <template>b/l/onestepcheckout/shipping_method.phtml</template>
        </action>
    </reference>
</b_onestepcheckout>

// either a_onestepcheckout or b_onestepcheckout depending on condition
<onestepcheckout_index_index>
    <update handle="a_onestepcheckout" /> or <update handle="b_onestepcheckout" />
</onestepcheckout_index_index>
Murtuza Zabuawala
  • 14,814
  • 9
  • 44
  • 75
Pradeep Sanku
  • 9,236
  • 2
  • 41
  • 73

1 Answers1

4

I don't think you can load a conditional layout handle from the xml.
You will have to do this in an observer.

Use the event controller_action_layout_load_before.
Something like this:

public function addSomeHandle($observer) {
    $action = $observer->getEvent()->getAction();
    $actionName = $action->getFullActionName();
    if ($actionName == 'onestepcheckout_index_index') { //if on your desired page
         $layout = $observer->getEvent()->getLayout();
         if (CONDITION GOES HERE) {
             $layout->getUpdate()->addHandle('a_onestepcheckout');
         }
         else {
             $layout->getUpdate()->addHandle('b_onestepcheckout');
         }
    }
}
Marius
  • 197,939
  • 53
  • 422
  • 830
  • thanks for answer.i tried this but i am getting error Fatal error: Call to undefined method Mage_Core_Model_Layout::addHandle() in Observer.php – Pradeep Sanku Apr 30 '14 at 11:16
  • @pradeepsanku. Oups. Sorry about that. I forgot an ->getUpdate() in the code. I've updated the code, try it now. – Marius Apr 30 '14 at 11:26