當我看事件checkout_onepage_controller_success_action
並且工作,但我無法獲得新創建的訂單的ID。Magento:獲取訂單ID,收聽事件checkout_onepage_controller_success_action
任何人有任何想法?
使用Magento的-1.4.1.0
感謝
當我看事件checkout_onepage_controller_success_action
並且工作,但我無法獲得新創建的訂單的ID。Magento:獲取訂單ID,收聽事件checkout_onepage_controller_success_action
任何人有任何想法?
使用Magento的-1.4.1.0
感謝
分派事件是這樣的:
Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));
因此,要獲得最後的訂單ID,只是讓你的觀測方法是這樣的:
public function orderSuccessEvent($observer)
{
$observer->getData('order_ids'));
}
這一事件可能會被調用的動作本身執行之前。你可以用sales_order_save_after
代替嗎?
編輯:這是您的ID代碼。在您的觀察:
public function setLinkStatus($observer) {
$order = $observer->getEvent()->getOrder();
$id = $order->getId();
// do something useful
}
這是布蘭科Ajzele提供的答案,我剛剛成功地測試:
$order = new Mage_Sales_Model_Order();
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order->loadByIncrementId($incrementId);
多虧了他,並希望它會工作。
在Magento的1.4版本的Onepage結帳控制器。 1不會更新爲具有可以獲取訂單ID的功能,因此您不能從事件觀察者獲得訂單對象和數據。要在Magento 1.4.1中使用此工具,只需使用必要的功能更新OnepageController。
最好的方法是創建自己的模塊並覆蓋核心控制器。
將此添加到模塊的config xml中,以便在覈心OnepageController之前調用您的控制器。
<frontend><routers><checkout><use>standard</use><args><modules><MyCompany_MyModule before="Mage_Checkout">MyCompany_MyModule</MyCompany_MyModule></modules></args></checkout></routers></frontend>
希望這有助於
這個答案應該被接受。 – 2016-05-25 11:22:08