0

I am looking for a way to list in a dropdown all events between when order is created and an order is finished (ie sales_order_shipment_save_after or sales_order_invoice_register) in the Admin panel. When whatever selected event is hit, then fire off whatever is inside my Observer (post to url). I am having an issue though as I understand you need to explicitly provide the event you want to trigger inside of your modules config.xml like so

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Modulename>
            <version>0.1.0</version>
        </Namespace_Modulename>
    </modules>
    <frontend>
        <events>            
            <checkout_submit_all_after>
                <observers>
                    <Namespace_Modulename_Customevent>
                        <type>singleton</type>
                        <class>Namespace_Modulename_Model_Observer</class>
                        <method>customFunction</method>
                    </Namespace_Modulename_Customevent>
                </observers>
            </checkout_submit_all_after>
        </events>
    </frontend>    
</config>

If this is the case then how would I be able to create a more configurable Event/Observer that would be able to handle admin specified events?

2 Answers 2

1

You will likely have to attach the event observer to all the events, then check at the start of the observer if the triggered event is the one configured in the admin panel:

public function myEventObserver(Varien_Event_Observer $observer)
{
    $eventName = $observer->getEvent()->getName();
    $configuredEvent = Mage::getStoreConfig('your/path/here');
    if ($configuredEvent !== $eventName) {
        return;
    }
    // your observer code
}
1
  • Great, what would my config look like in this case?
    – ehime
    Commented Mar 27, 2015 at 17:22
0

You can specify the admin event inside admin tag

...
  <admin>
     <events> 
        <sales_order_shipment_save_after> 
           <observers>
            <Namespace_Modulename_Customevent>
             <type>singleton</type>
             <class>Namespace_Modulename_Model_Observer</class> 
             <method>customFunction</method> 
            </Namespace_Modulename_Customevent>
          </observers>
       </sales_order_shipment_save_after> 

        <sales_order_invoice_register> 
           <observers>
            <Namespace_Modulename_AnotherCustomevent>
             <type>singleton</type>
             <class>Namespace_Modulename_Model_Observer</class> 
             <method>anotherCustomFunction</method> 
            </Namespace_Modulename_AnotherCustomevent>
          </observers>
       </sales_order_invoice_register> 

     </events>
  <admin>
...

Like this you can use many events in you custom module

4
  • So then would I need to add multiple event types inside the events tree? Plus 1 and waiting to see before I accept
    – ehime
    Commented Mar 27, 2015 at 17:21
  • @ehime check my edit Commented Mar 27, 2015 at 17:34
  • I did, I'm not sure if this is the best way to do this though at the minute.
    – ehime
    Commented Mar 27, 2015 at 17:35
  • yes, this the way to add event in your module Commented Mar 27, 2015 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.