7 replies [Last post]
Karel's picture
Offline
Joined: 06/13/2008
Juice: 19
Was this information Helpful?

Hello,

I have a funny problem - I need order id to be completely random, because currently, with a known website start date, clients (and competitors) can count number of store orders just by looking at order id. Unfortunately, the id is quite useful for identifying orders (e.g. over the phone), so I don't want to completely remove it (from users). I would like to make it a random, unique, 6-7 digit number - where should I look? Or is too difficult to accomplish?

Thanks, Karel.

Karel's picture
Offline
Joined: 06/13/2008
Juice: 19
Re: Random order id

OK, sorry. You really should allow Advanced search even for anonymous visitors:
http://www.ubercart.org/forum/support/755/sanitized_order_numbers

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Karel wrote:You really
Karel wrote:

You really should allow Advanced search even for anonymous visitors.

Good point. Done. Smiling

mikejoconnor's picture
Offline
AdministratorBug FinderGetting busy with the Ubercode.
Joined: 08/07/2007
Juice: 536
Re: Random order id

What about just using an md5 of the order id? 32 digits is a bit long, but it would appear random.

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Re: Random order id

order_id is a unique key in the DB. However you compute it, you have to guarantee it's unique, otherwise the insert query will fail and the order won't get stored. MD5 is a good hash, but it is just a hash, meaning there's no guarantee that two order_id numbers won't get hashed to the same value. Shouldn't happen often, but when it does you'll never figure out why the order failed!

<tr>.
half_brick's picture
Offline
Joined: 02/04/2008
Juice: 82
Re: Re: Re: Random order id

How's about changing the autoincrement increment in your database. With a little bit of work they could determine the increment, but it'd be a quick sorta-fix.

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#opti...

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Re: Random order id

Ah, that old thread of mine Smiling

Just to keep updated, I ended up making the new order numbers out of time(). I did it once and have left it alone, letting the usual db_next_id() function keep track of those order numbers.

I would love to be able to use alphanumerical combinations, but I suppose that isn't entirely necessary. Perhaps a "Customer order#" that would be more along the lines of a user-friendly number shown only to customers could be generated using a Contrib module, and this value added to forms and order screens. Not a huge deal, though - at least, not for us. Anymore. Smiling

--
Help directly fund development: Donate via PayPal!

pedrop's picture
Offline
Joined: 10/27/2011
Juice: 14
this simple module will do the job
<?php
/**
* Implementation of ubercart hook_order().
*/
function uc_random_order_id_order($op, &$arg1, $arg2) {

  if (

$op=='new') {

    if (isset(

$arg1->order_id) && (int)$arg1->order_id!=0) {
     
$try = 0;
      do {
       
$try++;
       
$new_id = rand(1000000, 9999999);
       
$res = db_query("UPDATE {uc_orders} SET order_id=%d WHERE order_id=%d", $new_id, $arg1->order_id );
      } while (
$res===FALSE && $try<5);
     
$arg1->order_id = $new_id;
    }

  }

}

?>
AttachmentSize
uc_random_order_id.tar.gz 636 bytes