Magento 1.7 – Order Number Issue

magento-1.7order-statussales-order

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?

Best Answer

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.

Related Topic