Get Order Increment Id in Magento

前端 未结 10 1711
生来不讨喜
生来不讨喜 2020-12-03 21:19

I\'m trying to get the Order Increment Id in Magento, on the success.phtml page so that I can use this for affiliate tracking.

I\'m using the following code, but it

相关标签:
10条回答
  • 2020-12-03 21:36

    I had to use...

    $_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
    

    While in the success.phtml template. Instead of load() I used loadByIncrementId - then my order object was no longer empty.

    0 讨论(0)
  • 2020-12-03 21:37

    getRealOrderId() appears to return the order number as presented in data grids. getId() will return the internal id of row in the database, which you probably don't want.

    0 讨论(0)
  • 2020-12-03 21:37
    $shipmentID = $shipment->increment_id;
    
    $order   = $shipment->getOrder();
    $orderID = $order->increment_id; 
    
    0 讨论(0)
  • 2020-12-03 21:45
    $lastOrderIncrementId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
    
    0 讨论(0)
  • 2020-12-03 21:50

    Your call to

    Mage::getSingleton('sales/order')
    

    isn't returning an object. Try

    var_dump(Mage::getSingleton('sales/order'));
    

    to confirm.

    I haven't dived into the checkout code recently, but I'm pretty sure that's because sales/order will get you the order in progress. Once the order's been placed it's no longer in progress.

    The "right" way to do this would be to create an observer for one of the events that Magento fires during checkout. The

    checkout_onepage_controller_success_action
    

    event should be sufficient, assuming you haven't done too much customization of the checkout process.

    There's a terse explaination of how to do this on the Wiki (for a different event)

    Once you get your event setup and responding, do a

    $event = $observer->getEvent();
    var_dump($event->getData());
    

    to see what kind of information you have available. Chances are there's an order object in there which will let you get the ID you're after.

    0 讨论(0)
  • 2020-12-03 21:50

    If you are in admin mode - try this:

    $orderModel = Mage::getModel('sales/order'); $orders = $orderModel->getCollection()->setOrder('increment_id', 'DESC')->setPageSize(1)->setCurPage(1); $orderId = $orders->getFirstItem()->getIncrementId();

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