I have a use-case where I need to know the order id from Magento before completing the order.

The idea is that I essentially call an API and if the API call is successful, then I proceed to complete the order, otherwise, I don't. The problem is that when I send the API call I need to send the order id as well.

I did this:

Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId() + 1

This obviously does not seem safe assuming multiple people are using the shop at the same time. Is there any way to predict what the final order id will be? Or to essentially get the last order id + "reserve" that order id + 1, and not affect the orders of other people that might be logged in at the same time?


Hello you can try this to get the latest order_id from the session:

  • will this work for having multiple parallel users? Imagine 100 people wait on the checkout page for a concert ticket for example. If I use this will the order id be different for all? – johnnyshrewd Mar 7 '19 at 23:13
  • yes it works , and the order id will be different as you want – sami23 Mar 9 '19 at 0:03
  • @johnnyshrewd you can test it by using different browsers and u will see that the increment id is different for every customer. Tell me if it works – sami23 Mar 10 '19 at 1:15

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.