Author Topic: Order number reformulation  (Read 46139 times)

joao

  • Beginner
  • *
  • Posts: 10
Order number reformulation
« on: October 29, 2004, 20:50:11 pm »
I would suggest not to use an order number but insted an 10 chrs hexadecimal (or other) reference.

It woul give more security to costumers .. this way no one would know eventual other's orders, and no new costumer would know how many orders the shop already did before him..

:)

Soeren

  • Administrator
  • Hero Member
  • *
  • Posts: 3106
  • VirtueMart Starter
    • virtuemart.net
Re:Order number reformulation
« Reply #1 on: October 30, 2004, 12:48:45 pm »
Why don't you post an example and some code for its generation?

ciao, soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

joao

  • Beginner
  • *
  • Posts: 10
Re:Order number reformulation
« Reply #2 on: October 31, 2004, 02:16:23 am »
well.. as for example ..

Order ref : A45F1C6FF4
Insted of : 00000001

I am no code wizard on PHP so i can't publish any code, but as for pseudo-code :

-> code generation by randomize and array of hexadecima chrs 'A'..'F' and '0'..'9' on a 10 item (or more) spaced table.
-> check if this new 10 hexa digit code already on database
->if code already on database get the 2 codes near (right after and right before) and see if possible to slip a new one in by semi-regen a new code from a newly regenerated array of chars from non-repeated chrs of the 2 closest codes. If possible insert it on database if not repeat the process until insertion is valid.

But another way.. easier and simpler (small is beautifull as always) is just to encrypt the actual sequence numbering with random seed given by a keycode on admin area from the admin, this way these references are unic for each site, and though the encryption algorithm is known, due to random seed, it is impossible (+/-) to track back.
So.. the encrypted reference should be the one given to costumer.. and SQL table linked the to original one that would e used only internally.

Sorry abt not supplying code.. but it was just an suggestion.. i dont program on php as i don't quite know the sintax although i've got an university mathematical computation degree (algo study).
 Sorry.. :(

chirng

  • Beginner
  • *
  • Posts: 13
    • gotham island forum
Re: Order number reformulation
« Reply #3 on: July 17, 2006, 10:33:41 am »
this very important to me also, is there any out come so far?

vmekk

  • Beginner
  • *
  • Posts: 28
Re: Order number reformulation
« Reply #4 on: August 14, 2006, 14:50:54 pm »
Hashing/encoding the ordernumers does not make it safer. It just makes it a lot more difficult to keep those orders apart.
Creating an order numbering system wich uses year, month day, and an ordernumber does the same thing you want, but it is a lot more easy to accept.
20060814003 means the third order on august the 14th in the year 2006

I agree on the fact that 20060814001 as your first real ordernumber is nicer to see than 00000001 :)

jaripetteri

  • Beginner
  • *
  • Posts: 9
Re: Order number reformulation
« Reply #5 on: October 18, 2006, 15:28:55 pm »
Has anyone done order number reformulation yet?

I'm looking for solution which would do as vmekk just describe but becouse databace acepts only 11 digits and I also need modulo137 check number i would like to put only two digits for a year. Like 16 = 2006 and 17 = 2007 -> 1608140015 and 5 is my modulo137 check number (probably no right on this on). This would acept 1000 order a day next 100 years so it should be enough...

I have already the code for the counting the modulo137 number but I just don't know where to put it on Virtuemart code... :(

any idea anyone?

Tristan L.

  • Beginner
  • *
  • Posts: 7
Re: Order number reformulation
« Reply #6 on: May 11, 2007, 20:30:50 pm »
What VirtueMart needs is this type of order number coding:
YYMMDD-HHMMSS-XXXX
E.g. 070511-202715-9384
       DATE-TIME-RANDOM

Where XXXX stands for any random number. This way you can receive 9999 orders per second. None of the customers is capable of finding out how many orders your webshop handles, this can create a sense of trust - which is very important online.

Is there a way of creating this possibility?

willowtree

  • Sr. Member
  • ****
  • Posts: 542
    • Willow Tree Crafts
Re: Order number reformulation
« Reply #7 on: May 03, 2008, 14:51:30 pm »
perhaps a more flexible solution would be to add an order_reference to each order, that could be generated in a number of ways.

I'm sure that some people like/need the sequential numbering which is acheived by the auto increment, whilst a number of people would prefer a non-sequential system.

If for example the order_number was modified perhaps with an encryption method as above there would be a reference number that was not sequential and that could be used in place of the order_number where required, such as in emails/displayed online etc.

Equally the order_reference could be randomly generated and not connected at all to the order_number. Encrypting the order_number would automatically generate a unique reference and would save the need to check the db for duplicates before saving.

Ideally there would also be a 'switch' in the VM config to use either order_number or order_reference which would set which the vendor wanted to use?
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

willowtree

  • Sr. Member
  • ****
  • Posts: 542
    • Willow Tree Crafts
Re: Order number reformulation
« Reply #8 on: May 03, 2008, 15:17:55 pm »
OK, just found that order_number is generated in this way, the order_id id encoded with an md5 hash.

Personally I find it too long to use as an order_reference, users will struggle to use it, but it's a starting point.
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

JoeP

  • Beginner
  • *
  • Posts: 48
Re: Order number reformulation
« Reply #9 on: September 03, 2008, 14:35:44 pm »
anyone figured out how to change order numbers from 000001 to something else yet?

willowtree

  • Sr. Member
  • ****
  • Posts: 542
    • Willow Tree Crafts
Re: Order number reformulation
« Reply #10 on: September 05, 2008, 17:28:22 pm »
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

sobers_2002

  • Beginner
  • *
  • Posts: 44
Re: Order number reformulation
« Reply #11 on: September 13, 2008, 12:53:36 pm »
I think the question was to modify the order no. generation scheme. I worked out a little something on that.

To change the order number generation do as follows:

1) Go to administrator/components/com_virtuemart/classes/ps_checkout.php

Find the following function - get_order_number()

and edit 
Code: [Select]
global $auth;

/* Generated a unique order number */

$str = session_id();
$str .= (string)time();
               
$order_number = $auth['user_id'] .'_'. md5($str);
               
return substr($order_number, 0, 32);


as follows
Code: [Select]
global $auth;

/* Generated a unique order number */

$str = session_id();
$str .= (string)time();
                $checksum = crc32($str);
                $date = date('Y-m-d');
                $order_number = $date . $checksum;

return substr($order_number, 0, 19);

This will give you an order number of the format YYYY-MM-DD-RANDNUMBR This gives us an order number, which is quite reasonably formatted and the uniqueness is still maintained.

Now, the order number should go like this and should be displayed in the account maintenance.

2) Go to administrator/components/com_virtuemart/classes/ps_order.php

at line 308 change
Code: [Select]
$q = "SELECT first_name,last_name,user_email,order_status_name FROM #__{vm}_order_user_info,#__{vm}_orders,#__{vm}_order_status "; to
Code: [Select]
$q = "SELECT first_name,last_name,order_number,user_email,order_status_name FROM #__{vm}_order_user_info,#__{vm}_orders,#__{vm}_order_status ";
at line 340 and 343, change
Code: [Select]
$d["order_id"] to
Code: [Select]
$d["order_number"]
This ensures that the user gets e-mailed about his order number, instead of order_id.

Now, in the account maintenance panel, displaying the order_number instead of the id is something I've not been able get to correctly work out, so if someone could get that working, this would be complete

EDIT: Was able to complete the whole job

3) In the same file, (administrator/components/com_virtuemart/classes/ps_order.php) at line 615 or find the code
Code: [Select]
$tmp_cell .= "<br /><strong>".$VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').":</strong> " . sprintf("%08d", $db->f("order_id"));
and change it to

Code: [Select]
$tmp_cell .= "<br /><strong>".$VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').":</strong> " . sprintf($db->f("order_number"));
and at line 559 change
Code: [Select]
$listfields = 'cdate,order_total,order_status,order_id,order_number,order_currency'; to
Code: [Select]
$listfields = 'cdate,order_total,order_status,order_id,order_currency';
4) Now, go to administrator/components/com_virtuemart/html/account.order_details.php and change the code

Code: [Select]
$mainframe->setPageTitle( $VM_LANG->_('PHPSHOP_ACC_ORDER_INFO').' : '.$VM_LANG->_('PHPSHOP_ORDER_LIST_ID').' '.$db->f('order_id'));
to

Code: [Select]
$mainframe->setPageTitle( $VM_LANG->_('PHPSHOP_ACC_ORDER_INFO').' : '.$VM_LANG->_('PHPSHOP_ORDER_LIST_ID').' '.$db->f('order_number'));
5) finally, go to components/com_virtuemart/themes/default/templates/pages/account.order_details.tpl.php

and change
Code: [Select]
<td><?php printf("%08d"$db->f("order_id")); ?></td> to
Code: [Select]
<td><?php printf($db->f("order_number")); ?></td>

As far as I have tested, this does not break anything and it very simple to implement. That said, it is a hack, and maybe someone should identify the changes that are to be made and integrate into the system as a changeable option. (ofcourse, the order_number generation is something that can be custom, but still...)

Hope this helps a lot of people. And maybe mods can sticky it ?

ErikZ

  • Beginner
  • *
  • Posts: 12
Re: Order number reformulation
« Reply #12 on: September 13, 2008, 16:53:17 pm »
This is so old. I checked out the areas I was supposed to modify, but the code has changed a lot in 4 years.

Considering how touchy VM can be, I wasn't willing to experiment.

sobers_2002

  • Beginner
  • *
  • Posts: 44
Re: Order number reformulation
« Reply #13 on: September 13, 2008, 20:57:26 pm »
this is with VM 1.1.2 and Joomla 1.5.6... as far as I know these are the latest versions. Unless you come from the future.

I realize this being posted in 1.0.x but I have msged the mod to move the topic to a more appropriate place.

sobers_2002

  • Beginner
  • *
  • Posts: 44
Re: Order number reformulation
« Reply #14 on: September 14, 2008, 08:01:50 am »
the above was incomplete... the user wasn't getting mailed with his order no. do the following for completion in file ps_checkout.php at
Code: [Select]
Email Addresses for shopper and vendor
replace
Code: [Select]
$shopper_subject = $dbv->f("vendor_name") . " ".$VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_LBL',false)." - " . $db->f("order_id");
with
Code: [Select]
$shopper_subject = $dbv->f("vendor_name") . " ".$VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_LBL',false)." - " . $db->f("order_number");
and at next line, again replace order_id with order_number

Then again, at
Code: [Select]
Main Email Message Purchase Order
replace order_id with order_number.

and again at somewhere near 2106 replace
Code: [Select]
'order_id' => $order_id with
Code: [Select]
'order_id' => $db->f('order_number')
The Order number inside the e-mail is still not coming.. I'll look into that.