Get Order Increment Id in Magento

前端 未结 10 1712
生来不讨喜
生来不讨喜 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:51

    If you're specifically doing this on the checkout success page - in success.phtml - then the code to get the order increment ID is already available in the template, since it is displayed to the customer.

    You just need the following:

    $orderId = $this->getOrderId();
    

    Note that this won't work on other pages so, for those, you'd need to use:

    $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
    
    0 讨论(0)
  • 2020-12-03 21:51

    $order in your code is the last order ID...as the function name implies. If this isn't the value you want, then use it to load an order, and then use the getter on that:

    $order = Mage::getModel('sales/order');
    $order->load(Mage::getSingleton('sales/order')->getLastOrderId());
    $lastOrderId = $order->getIncrementId();
    
    0 讨论(0)
  • 2020-12-03 21:57

    You can get the increment id using this code snippet:

    $orderId = 12;    
    $order = Mage::getModel('sales/order')->load($orderId);
    $Incrementid = $order->getIncrementId();
    

    Now you can do an echo to the $Incrementid variable and see the increment id.

    I hope this helps.

    0 讨论(0)
  • 2020-12-03 22:00

    This will work perfectly, I m running this one in my module now.

    $last_order_increment_id = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
    

    Hope it helps thanks. :)

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