|
Hi,
How do I create an observer for the “successful order”? Since I need to add additional data to the database with the order’s and user’s ID along with awarded points. Currently the way I do it is by adding it to the success.phtml and getting the last order’s info. Hower it is NOT guaranteed that the order will not be canceled (in which case I would need to rollback the awards, which I can’t). So I need something that can hookup to the observers and get executed once the order is fulfilled => when it no longer can be cancelled.
Here is the code I use in sucess.phtml:
$_customerId = Mage::getSingleton('customer/session')->getCustomerId(); $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId(); $order = Mage::getSingleton('sales/order'); $order->load($lastOrderId);
$_totalData =$order->getData();
$_grand = $_totalData['grand_total']; $_sub = $_totalData['subtotal']; $_ship = $_totalData['shipping_amount']; $_discount = $_totalData['discount_amount'];
$_total = $_sub - $_discount;
$_awards = floor($_total / $convertrate);
This however does not ensure that the order does not get cancelled.
How is this done the Magento way?
|