I have got a strange issue with Order Number in Magento.

Recently when one order was placed on my website the Order number came was 100000350,Ideally it should have been 100000370 as my previous order numbers were 100000369 and 100000367. I have attached the screenshot below for it

Order Number Screenshot

Moreover, I have checked for the error logs but haven't found any entry of it. We are using SagePay and PayPal as the payment gateway for it.

Can anyone guide me on this?

  • I can see clearly that you have install any module related to order taht's y this will arise a problem,
    – Keyul Shah
    Commented Sep 25, 2014 at 6:09
  • There is no module related to order.. the only third party module we are using are Ebizmarts_SagePay, Mass_Product_Relater, TBT_Enhancegrid and Sphinix Search
    – Dexter
    Commented Sep 25, 2014 at 6:16
  • 1
    No big issue, somebody with a customer account almost completed an order to the point it submitted for payment, got assigned a Sales Order number and then abandoned the cart for a period of time. Happens all the time... You got the order, congratulations, completed order instead of abandonment. Commented Sep 25, 2014 at 6:59
  • I think you didn't got my question
    – Dexter
    Commented Sep 25, 2014 at 7:40
  • 1
    @huzefam - Please take this up with the Magento design team, or create your own serial autonumber column that you key off of for your ERP on completed Magento SO. Yes, I understand from an auditing perspective if there are missing invoice numbers, there's hanky-panky. Magento seems to have taken the stance that not all orders are valid, therefore missing SO numbers are no big deal. I also understand that some accounting systems, government jurisdictions feel the same way about Sales Orders and expect to have an audit trail that shows voided orders in a complete serial sequence. Commented Sep 7, 2015 at 19:55

3 Answers 3


The first time I got an out of sequence number, we had surprise and some dismay until I figured out what was happening. It has to do with how Magento allocates Sales Order numbers.

It's entirely normal to have one out of sequence like that, be previous to the current allocated numbers and a month or more old. The secret to it is that it was a logged in customer who didn't complete the order after a certain critical stage, came back, logged in and decided to finally buy.

The quote with the allocated Sales Order number uses that number for the Sales Order number.

Now for the explanation.

The Magento order process creates a quote the first time something is added to the cart.

  • For guest customers, this quote lasts as long as their session has not timed out, at which point it exists in the database, but is not recoverable by the guest customer.
  • When a registered customer logs in, the cart quote gets assigned their customer id so that the cart lasts as long as the customer does not empty it and is retrievable by the registered customer by logging into their account.

At this point, the quote is a potential Sales Order only. It has no assigned number because the customer has not committed to paying for it.

As the customer clicks the Proceed Button to checkout, they will:

  • either be logged in previous to starting the cart
  • or if not logged in, asked if they want to register or check out as a guest.

What follows is an important bit: The customers who choose to register in the cart are treated as guest customers till the order is completed and they get to the success page, at which time their account is created and they're logged in. The quote remains a guest customer quote with the session timeout loss of cart if the order is not completed and a success page displayed.

With a credit card order, the following happens when the Place Order button is clicked.

  • The credit card information, billing address information, cart totals and order information are assembled
  • A Sales Order number is assigned for this quote (sales_flat_quote table in the reserved_order_id column)
  • The data package is submitted to the credit card gateway for authorizing/caputuring the funds to pay for the order.
  • The credit cart processor passes back:
    • either an authorization/capture of funds with the appropriate transaction information to be recorded
    • or rejection of payment with appropriate information as to why authorization/capture was denied.
  • With a successful authorization/capture, the quote is converted to a Sales Order and if this is a cart register, the customer account is created.

If the credit card transaction is declined for any customer by the credit card payment gateway, and the next customer places a successful order there will be a skip in the Sales Order number sequence due to the declined payment Sales Order being assigned a reserved Sales Order number and the following successful Sales Order being assigned the next available number.

For guest carts (guest orders and unsuccessful register in cart customers) that exceed the session timeout, this reserved Sales Order number will be lost when the session expires, leaving gaps in the Sales Order sequence.

For customers who logged in before clicking the Proceed Button, the quote is assigned a customer id, so if they attempt to place an order and find that it's declined, they can come back, log in, find the cart still has contents and place the order, sometimes much later (longest to date was four months). The quote will use the assigned reserved Sales Order number, leading to an out of sequence Sales Order number showing in your Sales Order management display.

  • For checking purpose, I pretended to get stuck in the checkout by not selecting the payment method and finally closing the browser (on the computer that opened the site + checkout first). and meanwhile finished the second computers order (which should get the next ID increment). The result is that it does not jump over the number. If it did work that way it would have added an unused ID between order 10 and order 11 which it did not. As per your information, I have tried to verify and do exactly the thing you are specifying but it is not giving the output.
    – Siva
    Commented Sep 18, 2018 at 6:18
  • Instead if a customer fails in Payement Gateway, it will show up as pending payment or canceled, and if the order is failed in the last part of the checkout that it will not show up at all (and just continue with the correct ID in the sequence). So now, I'm confused with this. Please help me to understand why the order number skips randomly. Thanks
    – Siva
    Commented Sep 18, 2018 at 6:18
  • Great Explanation.
    – Wolfack
    Commented Oct 30, 2019 at 18:17

I was facing the same issue but it was only when the server was hit with a huge amount of load. This issue occurs because the db goes into the lock state while converting quote into order. On further inspection, I found out that the issue was that it tried to write into sales_flat_order_grid table within transaction right after insert into sales_flat_order table. With concurrent queries it caused locking collisions. The real solution is to move stuff of sales_flat_order_grid out of the transaction.

The link helped me understand the issue

The patch resolved the issue for me.

You have to remove function _afterSave from the Mage_Sales_Model_Abstract and add

public function afterCommitCallback(){
    if (!$this->getForceUpdateGridRecords()) {

Let me know if it solves the problem for you.

  • Did anyone try this method as said by Shaily?
    – Siva
    Commented Sep 18, 2018 at 6:21

I am not sure, but this might solve your problem:

As far as I think, something might have disturbed your eav_entity_store table. It contains information about the next increment_id i.e. order_id to use. May be some module or code in your magento system might have changed it.

Open this table, and update the increment_last_id coloumn with your last order id. Be careful, it contains increment id's of others as well such as invoice, shipment etc. To be sure, just go to eav_entity_types table and see what is the entity_type_id for sales/order (column entity_model). In my magento, its 5. So now go to eav_entity_store table and just update the increment_id for row whose entity_type_id is 5. You can directly update it via phpmyadmin or you can run query like,

update eav_entity_store set increment_last_id = 'your_last_order_id' where entity_type_id = 5; 

Please note 5 is entity_type_id in my magento for order

There can be many reasons for your issue, but I think this might solve your issue.

  • Thanks.. but already checked the table and it has the correct increment id
    – Dexter
    Commented Sep 25, 2014 at 12:57
  • what is your maximum(not latest) order id in admin sales -> orders? Put that value in the table I said..place a test order and check..
    – Pradeep
    Commented Sep 25, 2014 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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