2015-11-03 75 views
0

將訂單放入我的magento商店後,我有一個自定義模塊,以便我可以將訂單號保存到外部數據庫表中。Magento - 一旦下單就獲得'getLastRealOrderId'

我的自定義模塊的設置是:

自定義/ ExternalOms/config.xml中

所以我掛接到sales_order_place_after事件

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <Custom_ExternalOms> 
      <version>0.0.1</version> 
     </Custom_ExternalOms> 
    </modules> 
    <global> 
     <models> 
      <custom_externaloms> 
       <class>Custom_ExternalOms_ExternalOms</class> 
      </custom_externaloms> 
     </models> 
     <events> 
      <sales_order_place_after> 
       <observers> 
        <custom_externaloms> 
         <type>model</type> 
         <class>Custom_ExternalOms_Model_ExternalOms</class> 
         <method>exportToOMS</method> 
        </custom_externaloms> 
       </observers> 
      </sales_order_place_after> 
     </events> 
    </global> 
</config> 

自定義/ ExternalOms /型號/ ExternalOms。 php

並運行我的功能:

class Custom_ExternalOms_Model_ExternalOms extends Mage_Core_Model_Abstract 
{ 
    public function exportToOMS() 
    { 
     $_order_number = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 

     // remaining code.. 
    } 
} 

的代碼運行一次訂單已放置正確,但這樣的:

Mage::getSingleton('checkout/session')->getLastRealOrderId(); 

快到了空

+0

您是否正在尋找的ENTITY_ID或increment_id? –

回答

0
Replace your event by this code 
     <events> 
        <sales_order_place_after> 
         <observers> 
          <custom_externaloms> 
           <type>model</type> 
           <class>externaloms/externalOms</class> 
           <method>exportToOMS</method> 
          </custom_externaloms> 
         </observers> 
        </sales_order_place_after> 
       </events> 


     ExternalOms file by this 

      class Custom_Externaloms_Model_ExternalOms { 
      public function exportToOMS($observer) 
       { 
        $observer->getOrder(); 

        // remaining code.. 
       } 

      } 
    /*  in case $observer->getOrder(); will not work than use 
        Mage::getSingleton('checkout/session')->getLastOrderId(); for getting last order id and load order 
      */ 
    I hope it will work 
相關問題