Jump to content

Archived

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

veverkap

Random Order Number

Recommended Posts

Warren,

 

The "$r1 = rand(10,99)" segment is a random numeral between 10 an 99.

The "$t1 = date("z-h-i-s")" segment is:

z= the number of the day of the year (April 24 is 113, I think)

h= hours

i= minutes

s= seconds

 

So, this "$ordernum = $t1.'tts'.$r1; " comes out like this: 113-06-37-12tts10. The hyphens in the date format stay in the actual number. So, this order was placed on the 113th day of the year, at 6:37:12 a.m. The "tts" is an abbreviation for my store name, and the two random digits after that are just to make it longer -- I doubt there is ANY chance of two people hitting the buy button at the exact same second.

 

Anyway, I have tested it on over 2 dozen orders, and it works like a charm. Because the date/time comes first, it allows for SIMPLE (automatic) sorting.

Share this post


Link to post
Share on other sites

I like it! - However, it is a tad long!!

 

If I wanted to make my own generate string - what would I have to put first to automatically sort it?

 

Is it the Z?

 

Warren

Share this post


Link to post
Share on other sites
I like it! - However, it is a tad long!!

 

If I wanted to make my own generate string - what would I have to put first to automatically sort it?

 

Is it the Z?

 

Warren

 

www.php.net/date


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Great - So it is the Z - However, what happens if the customer places two orders - one in 2003 and the other in 2004 - the years will get mixed in together - so it wont be in order!!

 

Warren

Share this post


Link to post
Share on other sites

Exactly.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites
Thats no good!!  :cry:  :cry:  :cry:  

 

Anythnig else to achive this?

 

Warren

 

date("U");


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Kewl - So it never get repeted what would be the ouput of that though?

 

Warren

Share this post


Link to post
Share on other sites

I had thought about the duplicate numbers across years problem, too. You could add the year into the number, as well. There are a lot of ways to use datetime snippets. A good reference can be found at http://wdvl.internet.com/Authoring/Languag.../PHP/Date_Time/

 

But how can we keep this from getting WAY too long...

Unless you figure your cart to get orders by the minute, the minutes portion could be dropped.

You can also drop the three alphabetical characters, if they don't mean much to you. (A hyphen could still separate numbers to make them easier on the eyes.)

 

So... $t1 = date("yz-hi-") would give you a 1-3 digit number for the day of the year, then a hyphen, then a 2 digit year number, 2 digit hour and 2 digit minute format -- WITH a hyphen at the right side...

 

Add $r1 = rand(100,999), and you would have a 3 digit random number after that hyphen (I have already hit a duplicate order number with only 2 digits -- in less than an hour of testing!).

 

And the end result could be...

 

 

//////////// RAMDOMIZING SCRIPRT BY PATRIC VEVERKA

///////modified by Eric Prochaska

 

srand ((float) microtime() * 10000000);

$r1 = rand(100,999);

$t1 = date("yz-hi-");

 

$ordernum = $t1.$r1;

 

///////////////// End of Randomizing Script

 

Here is an order number on a sample order:

03114-0729-786

 

2003+114 (114th day) - 7:29 - (random number between 100 and 999)

 

So... You can still sort easily, AND the randomness is retained, AND it's not TOO long, AND it is broken into easily understandable (by the store owner) segments.

 

What else should we do to it? :wink:

Share this post


Link to post
Share on other sites
Kewl - So it never get repeted  what would be the ouput of that though?

 

Warren

 

You'll never get the same number. Unless two people buy at the exact same second, so put a random letter or two on the end and you're done.

 

U is the number of seconds since the epoch 1/1/1970.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites
Kewl - So it never get repeted  what would be the ouput of that though?

 

Warren

 

You'll never get the same number. Unless two people buy at the exact same second, so put a random letter or two on the end and you're done.

 

U is the number of seconds since the epoch 1/1/1970.

 

You could even then write a simple little one liner to change the epoch time U to normal date/time and echo that result elsewhere. Simple.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Hmmm....

 

Fun this isnt it!!

 

What I have set up is a file containg three functions outputs...

 

$accnum - Customer Account Number

$ordernum - Order Number

$rmanum - RMA Number

 

What I could use is a single letter at the end (C, O or R) of an auto generating number which displays in date order...

 

What do you think?

 

Warren

Share this post


Link to post
Share on other sites

Warren,

Will using the account number in the order number prohibit you from allowing Guests to place orders?

 

-Eric

Share this post


Link to post
Share on other sites

No that is seperate....

 

the $accnum - is instead of using the one digit customer_id...

 

None of these are linked with each other!

 

Warren

Share this post


Link to post
Share on other sites
I loaded the random order number contribution and found that my download site... my downloads are not functioning anymore??? It was working before i installed the contribution and works when I reload my backup and edit the sql tables again.

 

I had the same problem until I removed the letters from the random order number. There is an if statement in downloads.php that checks for a numeric value in the order number. I tried removing that portion of the if structure, but it didn't work. There must be something elsewhere that doesn't like the letters.

 

Charlie

Share this post


Link to post
Share on other sites
//////////// RAMDOMIZING SCRIPRT BY PATRIC VEVERKA  

///////modified by Eric Prochaska

 

srand ((float) microtime() * 10000000);  

$r1 = rand(100,999);  

$t1 = date("yz-hi-");  

 

$ordernum = $t1.$r1;  

 

///////////////// End of Randomizing Script  

 

Here is an order number on a sample order:

03114-0729-786  

 

2003+114 (114th day) - 7:29 - (random number between 100 and 999)

 

So... You can still sort easily, AND the randomness is retained, AND it's not TOO long, AND it is broken into easily understandable (by the store owner) segments.  

 

What else should we do to it? :wink:

 

I think I'm going with:

 

srand ((float) microtime() * 10000000); 

$r1 = rand(1000,9999); 

$t1 = date("yz-His-"); 



$ordernum = $t1.$r1;

 

I pumped up the # of possible random#s, added seconds and changed the hours to a 24-hr clock, all to further reduce the possibility of any potential duplicates.

 

My first test run hit with an order# of: 03115-035512-7809

That's not too long for me. The only problem is that when the customer goes to the "Order History", the order# is truncated to 03115-03551 In the confirmation email it's the full deal, but on the Order History page it's not showing the full#

 

Hmmm... I should check to see if my admin order history truncates the# as well. Uh... okay, 2 things:

 

(1) Should I be able to see my Order # somewhere on the "Orders" page? I'm at admin -> customers -> orders I then select an order, click on "edit" "invoice" or "packing slip" but I don't see the order# listed anywhere.

 

(2) I can see my order# up in the URL bar but it's "oID=03115-03551" so obviously it's truncated as well. I think I may have problems since those first 10 digits are easily duplicated. What have I screwed up here?


Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Share this post


Link to post
Share on other sites

Ahhhh.... I need to go back into phpMyAdmin and change all those VARCHAR(11) to something like VARCHAR(17), yes?

 

Sorry, I'm new to this and just learned how to do ANYthing in phpMyAdmin about an hour ago. It takes me a bit :)


Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Share this post


Link to post
Share on other sites
Ahhhh.... I need to go back into phpMyAdmin and change all those VARCHAR(11) to something like VARCHAR(17), yes?

 

Sorry, I'm new to this and just learned how to do ANYthing in phpMyAdmin about an hour ago.  It takes me a bit :)

 

That should work. I believe the email makes use of the posted VAR which would make it correct on the email - obviously everything else takes it from the database. So if it's written in there truncated, then you have problems.

 

Try upping the characters as you've mentioned and let us know how you get on.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Mike,

I also had the truncated numbers in order history pages, and I also changed the number of characters in the database, which took care of it.

 

-Eric

Share this post


Link to post
Share on other sites
Ahhhh.... I need to go back into phpMyAdmin and change all those VARCHAR(11) to something like VARCHAR(17), yes?

 

Sorry, I'm new to this and just learned how to do ANYthing in phpMyAdmin about an hour ago.  It takes me a bit :)

 

That should work. I believe the email makes use of the posted VAR which would make it correct on the email - obviously everything else takes it from the database. So if it's written in there truncated, then you have problems.

 

Try upping the characters as you've mentioned and let us know how you get on.

 

Yup, that's exactly what I needed to do. Like I said, I'm just sort of bumbling my way through this :) Thanks


Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Share this post


Link to post
Share on other sites

To be arkward - I set mine to 15!! - I like to feel induvidual! :lol: :lol:

 

Warren

Share this post


Link to post
Share on other sites
To be arkward - I set mine to 15!! - I like to feel induvidual!  :lol:  :lol:

 

Well if your order numbers are longer than 15 digits, they might not feel so individual :)

 

I saw that you were doing something with customer and RMA numbers. What's the scoop? Share your code :)


Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Share this post


Link to post
Share on other sites
To be arkward - I set mine to 15!! - I like to feel induvidual!  :lol:  :lol:

 

Well if your order numbers are longer than 15 digits, they might not feel so individual :)

 

I saw that you were doing something with customer and RMA numbers. What's the scoop? Share your code :)

 

I will when I finish...

 

Warren

Share this post


Link to post
Share on other sites

I loaded the random order number contribution and found that my download site... my downloads are not functioning anymore??? It was working before i installed the contribution and works when I reload my backup and edit the sql tables again.

 

I had the same problem until I removed the letters from the random order number. There is an if statement in downloads.php that checks for a numeric value in the order number. I tried removing that portion of the if structure, but it didn't work. There must be something elsewhere that doesn't like the letters.

 

Charlie

 

Was this problem solved??

 

Warren

Share this post


Link to post
Share on other sites

OK - Heres what have in my global random number file...

 

<?php

////

//Generate an order number

$t1 = date("yz-");

srand ((float) microtime() * 10000000);

$input = array ("B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "T", "U", "V", "W", "X", "Y", "Z");

$rand_keys = array_rand ($input, 2);

$l1 = $input[$rand_keys[0]];

$l2 = $input[$rand_keys[1]];

$r1 = rand(1,9);



$ordernum = $t1.$l1.$l2.'-'.$r1.'-SA';



////

// Generate an account number

$t1 = date("yz-");

srand ((float) microtime() * 10000000);

$input = array ("B", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

$rand_keys = array_rand ($input, 2);

$l1 = $input[$rand_keys[0]];

$l2 = $input[$rand_keys[1]];

$r1 = rand(1,9);



$accnum = $t1.$l1.$l2.'-'.$r1.'-CA';



////

// Generate an RMA number

$t1 = date("yz-");

srand ((float) microtime() * 10000000);

$input = array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "N", "P", "Q", "S", "T", "U", "V", "W", "X", "Y", "Z");

$rand_keys = array_rand ($input, 2);

$l1 = $input[$rand_keys[0]];

$l2 = $input[$rand_keys[1]];

$r1 = rand(1,9);



$rmanum = $t1.$l1.$l2.'-'.$r1.'-RM';

?>

 

I then call this file from anyfile that requires an ID - Ad substitute the default with the outputs in this file....

 

Warren

Share this post


Link to post
Share on other sites

×