[ACCEPTED]-Get Order Increment Id in Magento-magento
If you're specifically doing this on the 7 checkout success page - in success.phtml 6 - then the code to get the order increment 5 ID is already available in the template, since 4 it is displayed to the customer.
You just 3 need the following:
$orderId = $this->getOrderId();
Note that this won't 2 work on other pages so, for those, you'd 1 need to use:
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order in your code is the last order ID...as 3 the function name implies. If this isn't 2 the value you want, then use it to load 1 an order, and then use the getter on that:
$order = Mage::getModel('sales/order'); $order->load(Mage::getSingleton('sales/order')->getLastOrderId()); $lastOrderId = $order->getIncrementId();
This will work perfectly, I m running this 1 one in my module now.
$last_order_increment_id = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
Hope it helps thanks. :)
Your call to
isn't returning an object. Try 16
I haven't dived into the checkout 15 code recently, but I'm pretty sure that's 14 because
sales/order will get you the order in progress. Once 13 the order's been placed it's no longer in 12 progress.
The "right" way to do 11 this would be to create an observer for 10 one of the events that Magento fires during 9 checkout. The
event should be sufficient, assuming 8 you haven't done too much customization 7 of the checkout process.
There's a terse 6 explaination of how to do this on the Wiki (for 5 a different event)
Once you get your event 4 setup and responding, do a
$event = $observer->getEvent(); var_dump($event->getData());
to see what kind 3 of information you have available. Chances 2 are there's an order object in there which 1 will let you get the ID you're after.
I had to use...
$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
While in the success.phtml 2 template. Instead of load() I used loadByIncrementId 1 - then my order object was no longer empty.
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();
getRealOrderId() appears to return the order number as presented 3 in data grids.
getId() will return the internal 2 id of row in the database, which you probably 1 don't want.
You can get the increment id using this 3 code snippet:
$orderId = 12; $order = Mage::getModel('sales/order')->load($orderId); $Incrementid = $order->getIncrementId();
Now you can do an echo to the 2 $Incrementid variable and see the increment 1 id.
I hope this helps.
$lastOrderIncrementId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();
More Related questions