4

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()

6

TL;DR: getLastRealOrderId => the increment ID (the order # shown to a customer after checkout. getLastOrderId => the entity ID of the order in the database.


Background

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.

4
  • I'm sending order id's/entity id's using curl/json for an approve conversion API. So it looks like i should be using getLastOrderId() rather than getLastRealOrderId()
    – thismethod
    May 27 '16 at 19:13
  • Can you confirm?
    – thismethod
    May 27 '16 at 21:12
  • Confirmed. <!-- more content -->
    – philwinkle
    May 27 '16 at 21:19
  • Thank you, the reason why i ask is because I'm nearly done but i'm still having an issue. This is for extole. Not sure if you're familiar with them. magento.stackexchange.com/questions/117406/…
    – thismethod
    May 28 '16 at 15:54
-1

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());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.