Tags/topics: 
2
Answers
Vote up!
4
Vote down!

How can I change the starting order number?

I recreated my old Ubercart store in Drupal Commerce, and I think the last thing I need to do is start the order numbers at a specific number. I couldn't get the migration to work so I just opted for a complete rebuild. Now I have no orders, but it's not a big problem if I can manage this task. Thanks.

Asked by: Sean
on June 1, 2012

Comments

2 Answers

Vote up!
7
Vote down!

Just a quick behind-the-scenes tidbit here: Drupal Commerce separates out its internal Order ID from what you see on the front end as the Order number. The Order ID is a serial numeric value that increments with each order created (including orders that are still shopping carts). The Order number can be any alphanumeric string, but it initializes to be the same as the Order ID. (Some sites then update orders upon creation to use a special alphanumeric order number format instead of the regular integer format.)

What you want to change is the AUTO_INCREMENT value on the commerce_order table. This will make it so the next created Order ID will start with the increased AUTO_INCREMENT value. By default when you create a new site, this will be set to 1, but feel free to set it as high as you need it to go. This is especially important if you're migrating an old site but using the same payment gateway, as they sometimes don't support the same order number being used twice.

The query to update this is:

ALTER TABLE  `commerce_order` AUTO_INCREMENT = 1000;

Where 1000 is replaced by whatever number you need the next created order to start at. This won't affect any existing order, just the next order to be saved to the database.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Jun 1, 2012

Comments

In the commerce_order table there are two fields - order_id and order_number. The SQL above certainly works and changes the counter to 1000. That would always be for the order_id field which is an int. Is there any way to change the values for order_number (varchar field type) to be different than order_id? say I wanted a special prefix for different product types? Is rules the solution?

- joemoraca on June 1, 2012


Some sites then update orders upon creation to use a special alphanumeric order number format instead of the regular integer format.

How do I do this? I can't see an appropriate Rules action.

- glennnz on August 9, 2012

On my Drupal Commerce store, the internal order_id is incremented by 5 instead of by 1. How do I change it to increment each order_id by 1?

I know how to change the starting order_id like this:

ALTER TABLE  `commerce_order` AUTO_INCREMENT = 1000;

but that's not what I'm trying to do.

The order_id's look like this:

  • 1005
  • 1010
  • 1015
  • 1020

I want them to look like this:

  • 1001
  • 1002
  • 1003
  • 1004

Is there some database setting that is causing these to be incremented by 5?

- Wesley Musgrove on September 28, 2015
Vote up!
0
Vote down!

Thank you, worked like a charm.

Answer by: ♥drea
Posted: May 19, 2014