Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Unique orders status id.


Dan Cole

Recommended Posts

I'm looking to update an old payment module Interac Email Money Transfer and it adds an orders status id to the database to set up an order status of "Waiting for Payment".  Unfortunately it just adds the orders_status_id of 4 in a table update as follows:

tep_db_query("insert into orders_status (orders_status_id, language_id, orders_status_name ) values ('4', '1', 'Waiting for payment')");

In my case I already have an orders_status_id of 4 in my database so it fails.  Obviously I can easily fudge the id in my case but if I'm going to upload the contribution back to the community it'll cause problems for others so I'm wondering if there is a simple way to just have it add a unique id to the database or if I need to query the database for the last added id and go from there?  That too is not a problem but this has me wondering if that is the best/simplest approach.  Suggestions anyone?

Dan

Link to comment
Share on other sites

tep_db_query("INSERT INTO orders_status (orders_status_id, language_id, orders_status_name ) SELECT MAX(orders_status_id) + 1, '1', 'Waiting for payment' FROM orders_status");

I believe that works.  Test of course.  First by running just the select in phpMyAdmin or similar and then try to write with it if the results are what you expect. 

Always back up before making changes.

Link to comment
Share on other sites

1 hour ago, ecartz said:

tep_db_query("INSERT INTO orders_status (orders_status_id, language_id, orders_status_name ) SELECT MAX(orders_status_id) + 1, '1', 'Waiting for payment' FROM orders_status");

I believe that works.  Test of course.  First by running just the select in phpMyAdmin or similar and then try to write with it if the results are what you expect. 

That's awesome and works perfectly.  Thanks Matt.  I appreciate it.

Dan

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...