Alex Rivera | Logout

Get Order Increment Id in Magento

Asked 2010-02-03T21:51:06.950
16

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 is giving an error on the second line;

$order = Mage::getSingleton('sales/order')->getLastOrderId();
$lastOrderId = $order->getIncrementId();

The error reads:

Fatal error: Call to a member function getIncrementId() on a non-object on line 34: $LastOrderId = $order->getIncrementId();

I was wondering if anyone has any ideas on how to get the Order Increment Id? This is the reference number seen in the admin, usually something like: #1000123

Edit
Report

1 Answer

7

$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();
answered 2010-02-03T21:59:04.020

Your Answer