veverkap Posted October 2, 2002 Share Posted October 2, 2002 I am trying to write a script that will substitute a partially randomized string for the order number (1,2,3, etc.). I have used the following script in PHP to make the random string: $t1 = date("mdy"); srand ((float) microtime() * 10000000); $input = array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "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(0,9); $ordernum = $l1.$l2.$t1.$r1; This would create a string like CE1002025, with the first two characters randomized, the middle six coming from the date and the last one randomized also. I have then successfully altered the array before tep_db_perform(TABLE_ORDERS, $sql_data_array); in the checkout_process.php file to insert the string as the orders_id in the orders table. (I additionally had to turn off auto_increment for the orders_id field.) My problem comes when I try to look at the account_history.php page. It lists the order four times. Does anyone know why it would do this? I can't see where it calls four times in the account_history.php file. Any help that I can get would be greatly appreciated. If you'd like to see the test site, it's at http://www.artoria.com/catalog/default.php Thanks, Patrick Patrick Link to comment Share on other sites More sharing options...
veverkap Posted October 7, 2002 Author Share Posted October 7, 2002 Can anyone help me with this, please? Patrick Patrick Link to comment Share on other sites More sharing options...
Guest Posted November 14, 2002 Share Posted November 14, 2002 I'd like to see that script working!!! Please someone help Patrick! Link to comment Share on other sites More sharing options...
Guest Posted April 14, 2003 Share Posted April 14, 2003 This script looks cool. I'd like to use it on my site too, competitors can see how many orders we get just by making fake orders even now and then, so a random order script sounds great. I ve been trying to figure out why duplicates 4 times the order... the only thing that rings a bell is: $ordernum = $l1.$l2.$t1.$r1; There is another way to do the random? Maybe the order gets 4 times posted in history because of that... Any other ideas? Link to comment Share on other sites More sharing options...
prosto Posted April 14, 2003 Share Posted April 14, 2003 I think the array you have to customize goes AFTER tep_db_perform(TABLE_ORDERS, $sql_data_array); not before. Also right after this line you have to comment out this $insert_id = tep_db_insert_id(); 2 lines down: (may be you have changed this already?) change this $sql_data_array = array('orders_id' => $insert_id, to this $sql_data_array = array('orders_id' => $ordernum, HTH Link to comment Share on other sites More sharing options...
brighthorizon Posted April 14, 2003 Share Posted April 14, 2003 I am trying to write a script that will substitute a partially randomized string for the order number (1,2,3, etc.). I have used the following script in PHP to make the random string: $t1 = date("mdy"); srand ((float) microtime() * 10000000); $input = array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "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(0,9); $ordernum = $l1.$l2.$t1.$r1; This would create a string like CE1002025, with the first two characters randomized, the middle six coming from the date and the last one randomized also. I have then successfully altered the array before tep_db_perform(TABLE_ORDERS, $sql_data_array); in the checkout_process.php file to insert the string as the orders_id in the orders table. (I additionally had to turn off auto_increment for the orders_id field.) My problem comes when I try to look at the account_history.php page. It lists the order four times. Does anyone know why it would do this? I can't see where it calls four times in the account_history.php file. Any help that I can get would be greatly appreciated. If you'd like to see the test site, it's at http://www.artoria.com/catalog/default.php Thanks, Patrick Here's my 2 cents maybe it will help you. Maybe this code here $ordernum = $l1.$l2.$t1.$r1; needs to be enclosed in quotes or brackets so $ordernum = ($l1.$l2.$t1.$r1); so that php sees it as one value? Let me know if you get it going I would also like a random order number generator. Hopefully, we can get this working I'm sure alot of people would benefit from this. Don't forget to package it and send it in as a Contribution. :) Link to comment Share on other sites More sharing options...
prosto Posted April 14, 2003 Share Posted April 14, 2003 nope this does not work sorry. will keep working on it. Link to comment Share on other sites More sharing options...
prosto Posted April 14, 2003 Share Posted April 14, 2003 I got it to work - here is what I did: 1. changed orders_id type from INT(11) to VARCHAR(11) in the following tables: orders orders_products orders_products_attributes orders_products_download orders_status_history orders_total 2. Pasted randomizing code right before this line // load the before_process function from the payment modules 3. changed $sql_data_array = array('customers_id' => $customer_id, to $sql_data_array = array('orders_id' => $ordernum, 'customers_id' => $customer_id, 4. Changed this $insert_id = tep_db_insert_id(); to this $insert_id = $ordernum; that's all. It shows just once in account history. Thanks a lot for the great idea!!!! Link to comment Share on other sites More sharing options...
brighthorizon Posted April 14, 2003 Share Posted April 14, 2003 Can you package your code into a Contribution to help the rest of us out??? Thanks!!! Link to comment Share on other sites More sharing options...
Guest Posted April 14, 2003 Share Posted April 14, 2003 Yeah, a packed contribution will be great, please do so we all can try it out on our sites!! Good job! Link to comment Share on other sites More sharing options...
prosto Posted April 14, 2003 Share Posted April 14, 2003 why don't you guys try it out now see if it works for you and then after blessing from Patric, who came out with the idea, we'll talk about contribution. May he can put one together... BTW, the contribution will be no different then the code above, it all manuall editing..... Link to comment Share on other sites More sharing options...
Guest Posted April 15, 2003 Share Posted April 15, 2003 I got it to work - here is what I did:1. changed orders_id type from INT(11) to VARCHAR(11) in the following tables: orders orders_products orders_products_attributes orders_products_download orders_status_history orders_total Ok, one question, did you turned off "auto_increment" or not? Thanks Link to comment Share on other sites More sharing options...
prosto Posted April 15, 2003 Share Posted April 15, 2003 yes, I did turn it off. Sorry, I missed it. Thanks Link to comment Share on other sites More sharing options...
Guest Posted April 15, 2003 Share Posted April 15, 2003 It's working, and now it is on my live shop! This is great! Ok, so who puts the contribution? Patrick please reply, it was your idea after all! Thanks to all who helped! Link to comment Share on other sites More sharing options...
brighthorizon Posted April 19, 2003 Share Posted April 19, 2003 Your contribution is a blessing... my store isn't live yet but I installed the contribution. It's working great!!! Thank you for sharing it.... It was very easy to install... :) Link to comment Share on other sites More sharing options...
brighthorizon Posted April 19, 2003 Share Posted April 19, 2003 Hello, 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. Does anyone know of a fix or know how to fix? So I can use the random order number contrib and still be able to use the download feature??? Thanks! Link to comment Share on other sites More sharing options...
Dusan Posted April 21, 2003 Share Posted April 21, 2003 This contribution really works great! But (iamneverhappyenough:) this order number could tell us even somthing more than date of order (first six numbers). And of corse, in admin section orders are no longer sorted because of VARCHAR instead of INT in products_id fields. Now we need another filed with increment auto_nubered filed :roll: I have found Perl script doing such job and now I wonder if someone could translate this in PHP: sub GenOrderNumber { my $S = shift; my $Name = ref $S ? shift || '' : $S; my $x = shift || ''; $Name =~ s/[^w ]/x/g; $Name =~ /(w)(w)*W*(w)?/o; my $Order = $1 || 'X'; $Order .= $3 || $2 || 'X' if $x; $Order = uc $Order; $Order .= ref $S ? GetTimeFields($S, qw(dayofyear secondofday)) : GetTimeFields(qw(dayofyear secondofday)); return $Order; } sub GetTimeFields { my ($x, $Out, @Out); my $Time = time(); my $S = shift; my @Fields = @_; if (ref $S) { $Time = $S->{-TIME}->{-LOCAL_TIME} if $S->{-TIME} && $S->{-TIME}->{-LOCAL_TIME}; } else { unshift @Fields, $S; } my $Map = _GetTimeX($Time); foreach $x(@Fields) { $x =~ tr/A-Z/a-z/; if (exists $Map->{$x} && defined $Map->{$x}) { if (wantarray) {push @Out, $Map->{$x};} else {$Out .= $Map->{$x};} } } return wantarray ? @Out: $Out; } sub _GetTimeX { my $Time = shift || time(); my @in = localtime($Time); return { 'second' => sprintf("%.2d", $in[0]), 'minute' => sprintf("%.2d", $in[1]), 'hour' => sprintf("%.2d", $in[2]), 'dayofmonth' => sprintf("%.2d", $in[3]), 'month' => sprintf("%.2d", ++$in[4]), 'shortyear' => sprintf("%.2d", substr($in[5], -2)), 'year' => sprintf("%.4d", '20'. substr($in[5], -2)), 'dayofweek' => $in[6], 'dayofyear' => sprintf("%.3d", $in[7]), 'secondofday' => sprintf("%.5d",($in[2] * 3600)+($in[1] * 60)+$in[0]), 'daysavingtime' => $in[8] }; } Generaly this is it. The order number is being generated based on the first letter from the user name, added the time of day in days in the year (3 digit), and seconds in the day (another 5 digit). The assumption here is that there will be no more than one order a second for a certain letter, which means a decent average of 5-8 orders a second (you wish you would have so many orders, you will be rich..) But of course, this is jus a hint... Have fun! Link to comment Share on other sites More sharing options...
burt Posted April 21, 2003 Share Posted April 21, 2003 Unlikely, but what happens when your randomness creates two order numbers exactly the same ? Link to comment Share on other sites More sharing options...
Waza04 Posted April 21, 2003 Share Posted April 21, 2003 Thats VERY unlikely - as the 4 digits that are randomised only have 24hrs to repeat... Warren Link to comment Share on other sites More sharing options...
burt Posted April 21, 2003 Share Posted April 21, 2003 <?php echo date("U"); ?> Seconds since 1/1/70 - add that to a couple of random letters...still possible to get two random order numbers the same, but much less likely than the other solution. Link to comment Share on other sites More sharing options...
prosto Posted April 22, 2003 Share Posted April 22, 2003 brighthorizon, Not sure why downloading section of your site isn't working - will look into that. As far as sorting of the orders - it is possible to make first two letter static to say reflect your store name and add seconds to the random order something like eg UE04220356 - then it will sort by date. Or it is possible to put random letters in the middle of the number like eg 0422UE0356 - then it wont be a mess... I think you could adust the script to your needs... Let me if you need help. Link to comment Share on other sites More sharing options...
prosto Posted April 22, 2003 Share Posted April 22, 2003 Also, to have your orders sorted by date, you can edit orders.php in catalog/admin. Look for this line f ($HTTP_GET_VARS['cID']) { and just below it you will see three lines starting with this $orders_query_raw In the end of each of these three query lines it is specified what to sort by order by order_id DESC order by o.order_id DESC and order by o.order_id DESC Change this to order by date_purchased DESC order by o.date_purchased DESC and order by o.date_purchased DESC and it should sort by date no matter what the order number is Link to comment Share on other sites More sharing options...
GaryM Posted April 23, 2003 Share Posted April 23, 2003 Thats VERY unlikely - as the 4 digits that are randomised only have 24hrs to repeat... Yeah, but no matter how unlikely it might be, Murphy says it's gonna' happen. And it will be on some major purchase in somebody's store that ends up bringing down the house, crashing the server, setting the roof on fire, pushing the owner over the edge, cats and dogs living together.... If something CAN happen, it WILL happen. It seems like when you're writing code it's better to fix the known conflicts instead of just relying on fate or chance that they probably won't occur. My 2-cents 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. Link to comment Share on other sites More sharing options...
Yikes Posted April 25, 2003 Share Posted April 25, 2003 Hi, all! I was fiddling around with the random order numbers (original contribution by Patric Veverka), and also had some of the concerns that have been voiced by others. My main concern was not having simplisitic order numbers, so using a date format in the number was my first plan. THEN, I also wanted some constant characters in the middle, to break up the long string of numbers for ease on the eyes. Finally, here is what I came up with: //////////// RAMDOMIZING SCRIPRT BY PATRIC VEVERKA srand ((float) microtime() * 10000000); $r1 = rand(10,99); $t1 = date("z-h-i-s"); $ordernum = $t1.'tts'.$r1; ///////////////// End of Randomizing Script What I have here is a date AND time format, but one which is not obvious ot customers. Then I have a three character string of constants. Finally, a random number (in double digits). The BEST part of this, on top of the other benefits I mentioned, is that THESE "randomly" generated numbers will stay IN ORDER in a customer's account history, and in your own e-mail, because of the "z" portion of the date/time segment. Anyway, I am high on my own cleverness and wanted to share since I have gotten so much from everyone else. Link to comment Share on other sites More sharing options...
Waza04 Posted April 25, 2003 Share Posted April 25, 2003 Hi Yikes! So if I was to use your script = What would be an example of a generated order number? Warren Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.