Questions? Answers.

Have a question? Post it and let the masses answer.
Tags/topics: 
1
Answers
Vote up!
3
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

1 Answer

Vote up!
4
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.

Answer by: Ryan
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
drupalcommerce Check out the #Drupal Commerce 2.x Roadmap to see where you can get involved: http://t.co/WAc3jmXY2a
drupalcommerce A new blog discussing the new showcase listing http://t.co/FHOzhAg3tl http://t.co/J5C87imjhb
drupalcommerce RT @drupalcon: Thanks @CommerceGuys and @CommerceJohn for your support, and for #CommerceKickstart! Take the tour http://t.co/ivKEYH7k0o
drupalcommerce Updating our extensions directory: 665 new or updated modules, distributions, sandboxes, & themes. http://t.co/6NMMofYo12 #weloveyouguys