Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento event always dispatched when order is placed successfully?

Tags:

magento

I'm finding Magento event dispatching is quite a frustrating area. I suppose a lot of that frustration is, as usual, down to the lack of documentation.

I would like my code to be triggered at various stages as a visitor traverses through a site. So I put some debug in Mage::dispatchEvent, and I walked through the site to see what events are fired at each stage. There are a lot!

Two places I am interested in are:

  • when the visitor had selected a billing address and moved on to the next stage of the checkout process.

  • when a user successfully places an order

For the billing address one, the events that I saw being fired that look relevant are:

controller_action_predispatch_checkout_onepage_saveBilling
controller_action_postdispatch_checkout_onepage_saveBilling

The 'pre' and 'post' suggested to me that there is actually a 'checkout_onepage_saveBilling' event, but there isn't, so my first question is why the 'pre' and 'post'?

For the successful order, the events that look good are:

checkout_onepage_controller_success_action
checkout_multishipping_controller_success_action

My second question is will these events be fired for all payment methods? For example, if using Google Checkout, or PayPal (standard redirect), will the event fire, and at what point? When returning to the site from PayPal? If so that would beg the question what if the user does not return after completing payment.

Thanks for any help.

like image 854
user265330 Avatar asked Nov 15 '11 11:11

user265330


2 Answers

Sadly, I've noticed that checkout_submit_all_after does not fire for Paypal Express orders.

Short of modifying the Paypal models to add this (or perhaps hooking into events they may fire - I haven't checked on that yet), I think checkout_onepage_controller_success_action may really be the only event you can absolutely count on for every type of order.

like image 105
Morgon Avatar answered Nov 19 '22 17:11

Morgon


The predispatch event will fire before the action has been called, the postdispatch event will fire after the action has been completed. So if you need to know what the result of the action was, you should use the postdispatch event.

For successful orders, checkout the checkout_submit_all_after event.

If you haven't seen it, https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/, is a handy reference for Magento events.

like image 32
Josh Avatar answered Nov 19 '22 17:11

Josh