URL: http://www.uburst.com/cgi-bin/dcforum/dcboard.cgi
Forum: ushop_prog_tips
Thread Number: 94
[ Go back to previous page ]

Original Message
"order number"

Posted by Thomas Huulbaek Andersen [webmaster@d-c-s.dk] on at 03:45 AM
I currently use the order number in the form of date and time down to the seconds. The problem is that we two times (because we have a lot of orders) encountered identical numbers. Is there a way to add fx. a tenth of a second? I can't do a random number because they have to be sequential because of the systems integration with our financial system.


Table of contents

Messages in this discussion
"RE: order number"
Posted by Bill Weiner on at 05:45 AM
As of uShop 3.4, you can specify the order number to be in one of three formats controlled by the "order_number_format" setting at the top of the ushop-lib.pl file:

$order_number_format = 0; # 0 = RRRRRRRRR
$order_number_format = 1; # 1 = MMDDYYYY-RRRRRRRRR
$order_number_format = 2; # 2 = DDMMYYYY-RRRRRRRRR

... where "MMDDYYYY" and "DDMMYYYY" is the date and "RRRRRRRRR" is a randomly generated number.

Since you mention that you are using the date & time in seconds... I'm guessing you implemented your own custom ordering scheme? If so, then you may want to add some sort of a check to ensure that the order number is not a duplicate...perhaps model it after the check we have in the "display_review_order_form" subroutine:

if ((-e "$data_directory$order_number.tmp" ) | |
(-e "$data_directory$order_number.order" ))
$order_number .= "2";
if ((-e "$data_directory$order_number.tmp" ) | |
(-e "$data_directory$order_number.order" ))
$order_number .= "$sec";

... where "2" or the current seconds ($sec) is added onto the original random order number if that original number already existed.

Of course, if the uniqueness of your order number is just being generated based on the time in seconds (as opposed to a randomly generated nubmer) ... then the above check may not work because obviously the time would be identical... an the other order file may not have been created yet. (Since it is all occuring simultaneously).

If you are looking to add tenths of a second to your order number - in order to keep you're numbers sequential and to decrease the possibility of identical order numbers - unforutately, the smallest time increment is seconds.... but there other things that can be done with some additional mods, here are a couple suggestions:

1) Technically, you could add a random number of zeros ("0") in front of your time in seconds in order to keep the number sequential... and unique. Ie. "0001", "00001", "002", "000002", .... And if necessary you can remove the extra zeros as last step of the order order process (in the "complete_order" subroutine) ... after make sure the order file is unique at that time.

2) Along the same lines as option 1, you could just use the standard uShop script... with the MMDDYYYY-RRRRRRRRRR format.... and only modify the last step in the order process (the "complete_order" subroutine) by setting the RRRRRRRRR to the seconds at that time and performing the existing file check at that time.

3) Or as an entirely diffent solution, you could try modifying the script such that a sequential order counter file is maintained ... and setup with a file-locking schema such that all order numbers are attained through that counter. (The biggest problem here, however, would be working out the file-locking mechanism to make sure only one order accesses/increments the file at a time.)

I hope this information helps.