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
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();
$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();
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.
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. :)