0

I am using multiple event observers in Magento 1.9

From there, I want to conditionally execute other observers. For example, defining the configuration in system.xml to enable or disable execution of observers after certain events.

In config I have this:

<events>
    <event_name>
        <observers>
            <observer_name>
                <type>observer_type</type>
                <class>observer_model</class>
                <method>method_to_call</method>
            </observer_name>
        </observers>
    </event_name>
</events>

Is there any configuration we can use here to enable/disable these observers?

1

Try this
In config.xml

<controller_action_layout_generate_xml_before>
     <observers>
          <add_new_layout>
              <class>wsafreightcommon/observer</class>
               <method>addNewLayout</method>
          </add_new_layout>
     </observers>
</controller_action_layout_generate_xml_before>

Observer.php

public function addNewLayout($observer){
      $layout = $observer->getEvent()->getLayout();
      $update = $layout->getUpdate();

      $action = $observer->getEvent()->getAction();
      $fullActionName = $action->getFullActionName();

      switch ($fullActionName) {
        case 'adminhtml_sales_order_view':
            $xml = "<reference name='root'><remove name='footer'></remove></reference>";
            $update->addUpdate($xml);
        ...
        break;
      }
//in case you're going to add some conditional (apply these new layout xml on these action or other things, you can modify it by yourself)

//here is the pieces of layout xml you're going to load (you get it from database)


return;} 

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.