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

后端 未结 4 1888
野的像风
野的像风 2021-01-15 16:24

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

相关标签:
4条回答
  • 2021-01-15 16:38

    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
    }
    
    0 讨论(0)
  • 2021-01-15 16:43

    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'));
    }
    
    0 讨论(0)
  • 2021-01-15 16:46

    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.

    0 讨论(0)
  • 2021-01-15 16:53

    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

    0 讨论(0)
提交回复
热议问题