Does anyone have a quick and dirty explanation of the differences?
Mage::getSingleton('checkout/session')->getLastOrderId()
Mage::getSingleton('checkout/session')->getLastRealOrderId()
I generally would use getLastOrderId()
TL;DR: getLastRealOrderId
=> the increment ID (the order # shown to a customer after checkout. getLastOrderId
=> the entity ID of the order in the database.
The method getLastRealOrderId
are magic methods, meaning they're getters for the properties last_real_order_id
and last_order_id
. They are set on the checkout session during a successful order placement by Mage_Checkout_Model_Onepage::saveOrder
.
The two data properties are set in tandem once the order is successful. - getLastRealOrderId
was introduced in Magento 1.8 CE on the checkout session along with the previously available getLastOrderId
because it would require another model load (e.g. another database query) get get the increment id, which is usually what you want, if you wanted access to that information to display on the site or use in code.
By setting it on the checkout session directly, when it's available, after a successful order they prevent a developer from writing code which may adversely affect performance.
You can get Order entity id from following line:
Mage::getSingleton('checkout/session')->getLastOrderId()
You can get Order Increment Id from following line:
Mage::getSingleton('checkout/session')->getLastRealOrderId()
For more clarification go to app/code/core/Mage/Checkout/Model/Type/Onepage.php
saveOrder method.
// add order information to the session
$this->_checkoutSession->setLastOrderId($order->getId())
->setRedirectUrl($redirectUrl)
->setLastRealOrderId($order->getIncrementId());