0

I am making my custom payment method module for Magento 1.9.1.1 and I want to do some action when user proceeds to checkout, before the order is placed, and after the order is placed. I implemented action for proceed to checkout event, and then I wanted to add an observer for event when order is placed. In my config.xml file I have this:

<events>
  <controller_action_predispatch_checkout_onepage_index>
    <observers>
      <mycheckout>
        <class>Custom_Paymentmethod_Model_Observer</class>
        <method>checkoutStarted</method>
        <type>singleton</type>
      </mycheckout>
    </observers>
   </controller_action_predispatch_checkout_onepage_index>
   <sales_order_save_after>
     <observers>
       <mycheckout>
         <class>Custom_Paymentmethod_Model_Observer</class>
         <method>initiateCheckout</method>
         <type>singleton</type>
       </mycheckout>
      </observers>
    </sales_order_save_after>
</events>

And in my Observer.php file I got:

class Custom_Paymentmethod_Model_Observer
{
    public function checkoutStarted(Varien_Event_Observer $observer)
    {
        //This action works fine
    }

    public function initiateCheckout(Varien_Event_Observer $observer)
    {
        //Nothing from here is triggered
    }
}

What am I missing here, and what is the issue?

And what event should I use before the order is placed?

1
  • What's exactly your problem? I mean, which event is not firing? None of them? Feb 5 '16 at 10:45
0

I believe you are wrongly using the event. I don't think there is an event called sales_order_save_after.

Use this event instead: sales_order_place_after and also change the observer name mycheckout to something else, anything, just need to be unique than what you have used earlier.

Each observer should be wrapped with a unique identifier.

So your code becomes this in config.xml:

<sales_order_place_after>
 <observers>
   <mycheckout_place_after>
     <class>Custom_Paymentmethod_Model_Observer</class>
     <method>initiateCheckout</method>
     <type>singleton</type>
   </mycheckout_place_after>
  </observers>
</sales_order_place_after>

Full list of events in magento here.

[UPDATE]

And what event should I use before the order is placed?

Events for order:

sales_order_place_after => this will fire after order is placed
sales_order_place_before => this will fire before order is placed
etc...

In fact, you could tell when they will be fired from their naming. This is good stuff from Magento team.

3
  • Thank you for pointing out that stuff, that's pretty useful to know! I changed like you proposed, but still not working. Now in my config file I have: <sales_order_place_before> <observers> <mycheckout_before_place> <class> Custom_Paymentmethod_Model_Observer </class> <method>initiateCheckout</method> <type>singleton</type> </mycheckout_before_place> </observers> </sales_order_place_before> And in my php file I put just redirection to google, to see if it will work, and still nothing.. Feb 5 '16 at 12:37
  • You can simply add this in your initiateCheckout function: Mage::log('fired', null, 'worked.log'); and then try with placing order, then check if there is file called worked.log in your var/log/ folder. Feb 5 '16 at 12:41
  • Fired! Checked my log file, everything worked ok, looks like for some reason redirection couldn't occur at that point, but now everything is ok. Thanks a lot! Feb 5 '16 at 12:46

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.