VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Feature requests => Topic started by: joao on October 29, 2004, 20:50:11 pm

Title: Order number reformulation
Post by: joao 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..

:)
Title: Re:Order number reformulation
Post by: Soeren on October 30, 2004, 12:48:45 pm
Why don't you post an example and some code for its generation?

ciao, soeren
Title: Re:Order number reformulation
Post by: joao 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.. :(
Title: Re: Order number reformulation
Post by: chirng on July 17, 2006, 10:33:41 am
this very important to me also, is there any out come so far?
Title: Re: Order number reformulation
Post by: vmekk 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 :)
Title: Re: Order number reformulation
Post by: jaripetteri 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?
Title: Re: Order number reformulation
Post by: Tristan L. 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?
Title: Re: Order number reformulation
Post by: willowtree 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?
Title: Re: Order number reformulation
Post by: willowtree 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.
Title: Re: Order number reformulation
Post by: JoeP on September 03, 2008, 14:35:44 pm
anyone figured out how to change order numbers from 000001 to something else yet?
Title: Re: Order number reformulation
Post by: willowtree on September 05, 2008, 17:28:22 pm
please try searching the forums,
http://forum.virtuemart.net/index.php?topic=40051.0
Title: Re: Order number reformulation
Post by: sobers_2002 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 ?
Title: Re: Order number reformulation
Post by: ErikZ 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.
Title: Re: Order number reformulation
Post by: sobers_2002 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.
Title: Re: Order number reformulation
Post by: sobers_2002 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.
Title: Re: Order number reformulation
Post by: sobers_2002 on September 14, 2008, 14:03:13 pm
the sum of above posts work like expected... I'll post a better looking and explained post (with hopefully cleaner way of doing things) soon!
Title: Re: Order number reformulation
Post by: sobers_2002 on September 15, 2008, 11:53:51 am
okay, bad news... there is a problem with the way things go on paypal. The order_id and order_number aren't working like supposed to and there is a problem with payments .. leading to orders not getting confirmed
Title: Re: Order number reformulation
Post by: kywolf on October 03, 2008, 20:39:12 pm
With a little tweaking this works...for the e-mail that is sent to the user.  It actually displays that order number on the users 'Account Maintenance' page also.

The problem is that it does not match up anything in the admin section.  The Order Number is the admin section still shows 00000XX.  I've tried updating order.order_list.php but I cannot get the back-end to match the changes made in the above emails.

Has anyone solved the other half of this equation - meaning updating the admin section of vm's order numbers?
Title: Re: Order number reformulation
Post by: sobers_2002 on October 05, 2008, 12:09:42 pm
@kywolf, good to know it works for you. The paypal issue that I was worried about was actually not a problem. It was a sandbox paypal issue which was causing it.

Anyways, I was working on other stuff for a while so I'll see on how to get it displayed in admin section.
Title: Re: Order number reformulation
Post by: saxmachine05 on January 16, 2009, 08:53:50 am
kywolf, this should work for you.

7) go to C:\wamp\www\toouch\administrator\components\com_virtuemart\html\ order.order_list.php
replace
Code:
$list  = "SELECT #__{vm}_orders.order_id,order_status, #__{vm}_orders.cdate,#__{vm}_orders.mdate,order_total,order_currency,#__{vm}_orders.user_id,";

with
Code:
$list  = "SELECT #__{vm}_orders.order_id,order_status,order_number, #__{vm}_orders.cdate,#__{vm}_orders.mdate,order_total,order_currency,#__{vm}_orders.user_id,";

replace
Code:
$q  .= "(#__{vm}_orders.order_id LIKE '%$keyword%' ";

with
Code:
$q  .= "(#__{vm}_orders.order_number LIKE '%$keyword%' ";


replace
Code:
$tmp_cell = "<a href=\"" . $sess->url($url) . "\">".sprintf("%08d", $db->f("order_id"))."</a><br />";

with
Code:
$tmp_cell = "<a href=\"" . $sess->url($url) . "\">".$db->f("order_number")."</a><br />";




8) Go to C:\wamp\www\toouch\administrator\components\com_virtuemart\html\ order.order_print.php
replace
Code:
<td><?php printf("%08d", $db->f("order_id"));?></td>

with
Code:
<td><?php printf($db->f("order_number"));?> </td>

Title: Re: Order number reformulation
Post by: kywolf on February 12, 2009, 22:25:53 pm
@saxmachine05 - thanks for posting that info - worked perfectly

I finally had a chance to go back through the instructions in this post and after all the changes, my order numbers are finally customized to my site instead of the random digits.

Thanks to everyone who posted!
Title: Re: Order number reformulation
Post by: saxmachine05 on August 29, 2009, 10:57:53 am
@kywolf, you are most welcomed :)
Guys, I've been working out the ebay checkout system where you can actually invite your ebay customer to check out the won ebay item on your Virtuemart website.

More news is updated on this thread https://forum.virtuemart.net/index.php?topic=45662.new;topicseen#new

Stay tuned :)
Title: Re: Order number reformulation
Post by: jarozz on February 06, 2010, 20:12:36 pm
everythig is working fine, just when changing status of order, email to customer contains old numbering - 00000xx
can you help me check this ?
thank you.
Title: Re: Order number reformulation
Post by: josenova on April 21, 2010, 22:55:08 pm
maybe I missed something, but now on the account maintenance there is no order number displayed at all. When you click on order details tho, the correct order number is displayed.

What did I miss?
Title: Re: Order number reformulation
Post by: stinga on April 22, 2010, 00:30:04 am
Why on earth would you want to munge the order number? I can't see any reason for it other than creating work for the sake of it, now you have made the change you are going to have to repeat the change on every upgrade
Title: Re: Order number reformulation
Post by: josenova on April 22, 2010, 09:42:42 am
hmmm that was helpful
Title: Re: Order number reformulation
Post by: stunami on May 23, 2010, 02:46:40 am
I make this change to every site I develop because order I prefer not to show customers how many orders an online shop has taken. Order numbers involving the date are also arguably more meaningful than the default numbering system.

cheers, stu
ps. These changes work with 1.1.4
Title: Re: Order number reformulation
Post by: Eugen S. on August 08, 2010, 14:07:28 pm
this is probalbly the best topic in the forum.

Many thanks to sobers_2002.


I want to make a supplement. If somebody want a order number like:

Your_Name order_number - date

for example Nike 234 - 08.08.2010

use the following code to replace in the first step

function get_order_number() {
      global $auth;

      /* Generated a unique order number */

      $str = session_id();
      $str .= (string)time();
      $date = date('d.m.Y');
      
      $db =& JFactory::getDBO();
      $query = "   SELECT order_id
                FROM #__vm_orders ";
      $db->setQuery($query);
      $column= $db->loadResultArray();
       $anzahl = count($column) + 1;
   
      $order_number = "Nike ".$anzahl." - ".$date ;
               
      return substr($order_number, 0, 32);
   }
Title: Re: Order number reformulation
Post by: Roger Lightening on August 11, 2010, 09:04:43 am
Thanks for your help sobers_2002!
Title: Re: Order number reformulation
Post by: ronz on January 23, 2011, 00:31:23 am
and at line 559 change
Code:

$listfields = 'cdate,order_total,order_status,order_id,order_number,order_currency';

to
Code:

$listfields = 'cdate,order_total,order_status,order_id,order_currency';

The new version of VM has the following code instead:
$listfields = 'o.order_id,o.cdate,order_total,o.order_status,order_currency';

What should I change to then? I tried change to o.order_number but no luck...Anyone can help?
Title: Re: Order number reformulation
Post by: edemict on April 15, 2011, 14:58:02 pm
I equally have the same problem, my order number generated from this post is not showing in the mail sent out to users. Please i need help.
The order number shows in every other field both in the front end account maintenance and the back end order list. Please can someone help.
Title: Re: Order number reformulation
Post by: avedis777 on July 03, 2011, 02:47:45 am
Hi, I am trying to change the order numbers displayed from the 0000001 scheme to to something else...preferably something like starting at 1500 or some larger number like that, I do not need any kind of date code at this point.

From sobers_2002 posting, step 1 there is the function get_order_number() in the ps_checkout.php file...is this the function that generates the order number?

The code after the first step confuses me because I'm not sure why we are changing things from the order_id to the order_number...if things are displaying the order_id rather than the order_number, maybe I just need to change how the order_id is generated instead of the order number?

This seems like it would be simple, but I'm kind of confused about what I need to change to have the orders start at a number larger than 1.

Any direction would be appreciated.

Thanks!
Title: Re: Order number reformulation
Post by: jenkinhill on July 04, 2011, 18:08:11 pm
http://forum.virtuemart.net/index.php?topic=76126.0
Title: Re: Order number reformulation
Post by: andyjudge85 on July 07, 2011, 16:58:00 pm
Hello friends sorry if my post is not helpeful for any friend. I had problem to change order number series but i have sort it out. i was trying to change order number in phpmyadmin but my orders numbers was not changing they was going to back to old series. but its possible to change we just have to do after changing order number go to tab Operations in Phpmyadmin and left side in Table options column in field AUTO_INCREMENT add there one + plus value then your order number. For e.g ( if you have insert order number 99 then add AUTO_INCREMENT 100 ).  :) . and please excuse my English.
Title: Re: Order number reformulation
Post by: lalmohan on February 15, 2012, 08:08:19 am
and at line 559 change
Code:

$listfields = 'cdate,order_total,order_status,order_id,order_number,order_currency';

to
Code:

$listfields = 'cdate,order_total,order_status,order_id,order_currency';

The new version of VM has the following code instead:
$listfields = 'o.order_id,o.cdate,order_total,o.order_status,order_currency';

What should I change to then? I tried change to o.order_number but no luck...Anyone can help?
Title: Re: Order number reformulation
Post by: laithdarant on September 18, 2012, 17:52:34 pm
Hi, I've followed every step in this thread, but I have one problem I can't solve, when I update the order status and select to notify the client, there's a message
Quote
Advertencia: No ha podido mandar el mensaje a , ()
In English it means that The message could no be sent, somone has any idea how to solve it?
Title: Re: Order number reformulation
Post by: elvispl on October 25, 2012, 11:29:18 am
and at line 559 change
Code:

$listfields = 'cdate,order_total,order_status,order_id,order_number,order_currency';

to
Code:

$listfields = 'cdate,order_total,order_status,order_id,order_currency';

The new version of VM has the following code instead:
$listfields = 'o.order_id,o.cdate,order_total,o.order_status,order_currency';

What should I change to then? I tried change to o.order_number but no luck...Anyone can help?

$listfields = 'o.order_id,o.cdate,order_total,o.order_status,order_number,order_currency';
Title: Re: Order number reformulation
Post by: bobysolo on July 10, 2013, 18:45:16 pm
I know this topic is old, but still, I need a further customisation regarding order_id.

Is it possible to also modify order_id in the frontend URL?

So that instead of this:
index.php?page=account.order_details&order_id=1&option=com_virtuemart&Itemid=101
we'll have this:
index.php?page=account.order_details&order_number=2013-07-60283548122&option=com_virtuemart&Itemid=101

Because now we have cleared the order_id from every aspect of VM except the URL.

Thanks ;-)
Title: Re: Order number reformulation
Post by: bobysolo on July 21, 2013, 22:03:31 pm
If someone else needs to reformulate the past order numbers, so that they match the new formula, here is the SQL query:

Code: [Select]
UPDATE `BBB_vm_orders` SET `order_number`= concat(DATE_FORMAT(FROM_UNIXTIME(cdate), '%Y-%m-%d'), "-",RPAD(CRC32(TIME_FORMAT(FROM_UNIXTIME(cdate), '%H:%i:%s  ')), 8, ceil(RAND()*10)) )
where order_id <= 4323

Change the "BBB" in the "BBB_vm_orders" so that it matches your DB prefix.

What the query does is to update the past order_number column, creating a new order_number format like this: "YYYY-MM-DD-12345678" - date + 8 random numbers. For me I needed to reformulate the orders from the ID 4323 down - so change you order_id accordingly.

Thank you Matej (http://www.linkedin.com/in/matejleban) for this.