Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: Change Order ID to random number?  (Read 772 times)

Offline masalachai

  • Newbie
  • *
  • Posts: 25
  • Karma: +3/-0
    • View Profile
Change Order ID to random number?
« on: July 04, 2018, 06:19:49 AM »
Perhaps this has already been asked, but is there a way to change the Order ID to a random number, say 8-16 digit alpha-numeric (like PayPal does)?
Another application is osTicket, which lets the admin choose the option 'Sequential' or 'Random' for the ticket numbering. Something like that.  Thanks!
« Last Edit: July 04, 2018, 06:53:03 AM by masalachai »

Offline jaja

  • Newbie
  • *
  • Posts: 33
  • Karma: +10/-0
    • View Profile
Re: Change Order ID to random number?
« Reply #1 on: July 04, 2018, 08:42:19 AM »
you cant do this for order id but seems to be possible for invoice number

Offline masalachai

  • Newbie
  • *
  • Posts: 25
  • Karma: +3/-0
    • View Profile
Re: Change Order ID to random number?
« Reply #2 on: July 05, 2018, 05:46:29 AM »
I *think* a unix timestamp will do the trick (it's a unique long string of numbers). Just have to add a column to the 'orders' table and figure out how to modify the script that posts to it, then call that column for the Order ID in the customer confirmation email.


UPDATE
Making some progress!
I added the column 'unix' to the 'orders' table in MySQL and set it to bigint(32)
Then I modified the order.php page [storefront/model/checkout/order.php]  and inserted the following code at line 215
unix = NOW(),

On checkout, this inserts a numeric string like 20180705230844 in the 'unix' column.

Now working on how to modify the order_confirm.tpl to use the 'unix' column instead of the 'order_id' in the email send.

UPDATE #2
Got it!  :)

Changed line 409 of order.php to
$subject = sprintf($language->get('text_subject'), $order_row['store_name'], $order_row['unix']);

Inserted to order.php on line 451
$this->data['mail_template_data']['unix'] = $order_row['unix'];

Changed line 29 of order_confirm.tpl
<td class="align_left"><?php echo $text_order_id; ?> <?php echo $unix; ?><br/>

UPDATE #3
Changed line 409 to just plain text
$subject = sprintf('Receipt for Your Payment to Example');

Changed line 29 of order_confirm.tpl
<td class="align_left"><?php echo 'Order Number:' ?> <?php echo $unix; ?><br/>

Also timezone was wrong, so added to the top of php.ini
date.timezone = "America/Los_Angeles";

UPDATE #4
Although timestamp is a unique number, I wanted the Order Number in the email send for the customer to be more random in it's appearance, and also shorter in length.
My solution was to simply take the timestamp and subtract year,month,day:

Changed line 215 in order.php:
unix = NOW()-201807050000,

Ex.
Order Number: 20115930

« Last Edit: July 25, 2018, 01:05:04 PM by masalachai »

Offline AVS

  • Newbie
  • *
  • Posts: 42
  • Karma: +6/-0
    • View Profile
Re: Change Order ID to random number?
« Reply #3 on: December 10, 2018, 02:38:21 AM »
Hi
Thanks for sharing this. I tried, but the generated random number not getting inserted in Order ID in body of email sent to customers though it show in subject of email. Also order page when clicked does not show random number but it shows Original order ID field number. Can you please tell what i am missing?
Thanks

UPDATE:

I modified Mail template and it works now  sending  unique ID to customers instead of default Order ID. But this new field Unix value could not be shown in Invoice page or Order history page.
I tried to  modify Invoice but the value does not appear. How to retrieve this data from database and show in the invoice as Order ID ? Can you please suggest?
Thanks
« Last Edit: December 14, 2018, 01:18:29 AM by AVS »

 

Powered by SMFPacks Social Login Mod