Magento: Obtain Id for order, listening to the event checkout_onepage_controller_success_action

StackOverflow https://stackoverflow.com/questions/3676941

  •  01-10-2019
  •  | 
  •  

Question

When I look at the event checkout_onepage_controller_success_action and works, but I can not get the Id of the newly created order.

Anyone have any idea??

Use magento-1.4.1.0

Thanks

Was it helpful?

Solution

The event is dispatched like this:

Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));

So to get the last orderId, simply make your observer method like this:

public function orderSuccessEvent($observer)
{
    $observer->getData('order_ids'));
}

OTHER TIPS

This is an answer provided by Branko Ajzele and I've just successfully tested:

        $order = new Mage_Sales_Model_Order();
    $incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
    $order->loadByIncrementId($incrementId);

Thanks to him and hope it'll work.

That event probably gets called before the action itself executes. Can you use sales_order_save_after instead?


EDIT: Here's your ID code. In your observer:

public function setLinkStatus($observer) {
    $order = $observer->getEvent()->getOrder(); 
    $id = $order->getId();

    // do something useful
}

The Onepage Checkout controller in the Magento version 1.4.1 is not updated to have functions that can obtain the Order ID and thus you cant have the order object and data from the event observer. To have this working in Magento 1.4.1 simply update your OnepageController with the necessary functions.

The best approach would be to create your own module and override the core controller.

Add this in the config xml of your module so that your controller is called before the core OnepageController.

<frontend><routers><checkout><use>standard</use><args><modules><MyCompany_MyModule before="Mage_Checkout">MyCompany_MyModule</MyCompany_MyModule></modules></args></checkout></routers></frontend>

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top