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

梦想与她 提交于 2019-12-01 09:39:06
Hans Stevens

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'));
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!