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

给你一囗甜甜゛ 提交于 2019-12-01 08:28:45

问题


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


回答1:


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



回答2:


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.




回答3:


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
}



回答4:


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



来源:https://stackoverflow.com/questions/3676941/magento-obtain-id-for-order-listening-to-the-event-checkout-onepage-controller

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