Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

How can I add a prefix to order_id ?


Recommended Posts

Hello all,


I'm sure I'm not the first to ask this, but after much searching I can't find a post in the forums so here goes.


I need to add a prefix to the order_id so it cannot have the same order number as an order placed outside of osc, to make for clear and simple accounting. For example I'd like the order_id / order number format to be something like WEB-1 instead of just 1. Where is order_id generated and is it possible to automatically add a prefix when it is generated?


In checkout_process.php starting around line 97 is this code:


  $insert_id = tep_db_insert_id();
 for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
$sql_data_array = array('orders_id' => $insert_id,
						'title' => $order_totals[$i]['title'],
						'text' => $order_totals[$i]['text'],
						'value' => $order_totals[$i]['value'], 
						'class' => $order_totals[$i]['code'], 
						'sort_order' => $order_totals[$i]['sort_order']);
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);


Is this the right place to start?


Is $insert_id = "WEB-" . tep_db_insert_id(); the right sort of thing to do?




The more I look at it the more confused I get!



Please help,



Link to comment
Share on other sites

Nice idea but i wouldn't do that! That is just one of a few tables that are related to an order (orders, orders_products,orders_products_attributes, orders_status_history etc) they all need the orders id to link. Also the field you would put that in is an int so it would error anyway. Have a search in the contributions section. There are contributions that will do what you want. "why re-invent the wheel"


Also just incase you do decide to go down that route, you must assign that insert id to $insert_id, there are other parts of that page that use it.




Link to comment
Share on other sites



I had hoped to effectively alter the system of order numbering used by osc, but as you've confirmed it would be a pretty complex task. I had searched through the features contri and not found much, but on searching through all the contris I've found a couple that might do the trick with a little fiddling...



Link to comment
Share on other sites

Turns out the simplest way is use phpmyadmin or whatever to change the last order_id to 1000000001.


If we get round to taking a billion orders then I altering osc to fit will be a small price to pay! :)



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...