Jump to content

How to change the Order Reference to Number Reference


Recommended Posts

Hi guys,

 

Using new version of Prestashop 1.5.2.0. I would like to change the Order reference ( alphabets ) to alphanumeric value. I tried searching in forums and Seen this forum. Unfortunately it wont work for me.

 

Can any one have solution to change Order reference ( alphabets ) to alphanumeric value in entire application.

 

I mean "AQMKATRQG" to "AK1001" and the increment it to "AK1002"

 

Thanks in advanced. I am in only hope of getting solution from helping hands.

Edited by Gany.akshu (see edit history)
Link to comment
Share on other sites

Thank you for this. If i want ALPHANUMERIC values. I have edited your code as below.

 

" / classes / order / Order.php "

 

return strtoupper (Tools :: passwdGen (9 'ALPHANUMERIC'));

 

And in The file ' / classes / Tools.php "

 

public static function passwdGen ($ length = 8, $ flag = 'ALPHANUMERIC') {

switch ($ flag) {

case 'NUMERIC':

$ str = '0123456789 ';

break;

case 'NO_NUMERIC':

$ str = 'AK';

break;

default:

$ str = 'abcdefghijkmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

break;

}

for ($ i = 0, $ passwd =''; $ i <$ length, $ i + +)

$ passwd. = Tools :: substr ($ str, mt_rand ( 0, Tools :: strlen ($ str) - 1), 1);

return $ passwd;

}

 

So that I can get the order reference as only AK(Numberic) values.

 

Please correct me if I am wrong.

Link to comment
Share on other sites

Hello!

How are you?

The default function is eight alphanumeric characters.

If you want to change the default function for nine characters and call without passing parameters, so it runs in your default template.

Create a new standard, if you want, and enter a prefix or suffix as well understood. You can concatenate your code AK + X sequence of numbers or letters or alphanumeric characters.

Hugs!

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 4 months later...

thinks,

 

I'm using PS 1.5.1, so it's line 77

 

or you can find this code, {$order->getUniqReference()} and replace with code that I gave before.

 

 

saya buat kenapa tak jadi ye. saya guna version 1.5.2.0

end result sama je, tetap alphabet yang tonggang langgang tu..huhu. boleh tolong x?

Link to comment
Share on other sites

Guys,

 

For order number, I'm using order id instead of reference and it's same as you can see in the Order history.

 

Go to pdf/invoice.tpl (line: 77) and change to this code

 

{l s='#'}{$order_invoice->id_order|string_format:"%06d"}

 

Thanks Mohamadeffazuan, this works :)

Link to comment
Share on other sites

  • 5 months later...
  • 1 month later...
  • 3 months later...
  • 2 months later...

Guys,

 

For order number, I'm using order id instead of reference and it's same as you can see in the Order history.

 

Go to pdf/invoice.tpl (line: 77) and change to this code

 

{l s='#'}{$order_invoice->id_order|string_format:"%06d"}

Worked like Charm thanks

Link to comment
Share on other sites

  • 9 months later...

For anyone who would like to reinstate the default behaviour of PrestaShop v1.4 where orders are assigned an ascending numerical order number prefixed with zeros instead of what would appear to be 9 random letters, I have posted the source code and method in response to someone's question on the StackOverflow website:

 

How to change the order reference to number reference

 

Modifications to the source code to change the numerical order number to include an alphanumeric prefix would not be difficult.

  • Like 1
Link to comment
Share on other sites

For anyone who would like to reinstate the default behaviour of PrestaShop v1.4 where orders are assigned an ascending numerical order number prefixed with zeros instead of what would appear to be 9 random letters, I have posted the source code and method in response to someone's question on the StackOverflow website:

 

How to change the order reference to number reference

 

Modifications to the source code to change the numerical order number to include an alphanumeric prefix would not be difficult.

 

A big THANKS Richard! 1.6.0.14 version here -  been trying to find a simple solution via .php editing, avoiding modules to install and here is Your post with everything I need! Thanks a bunch! Works like charm! If I see any issues with the code I will surely update this answer. But so far - so good :)

 

Thanks again!

Edited by sting5 (see edit history)
Link to comment
Share on other sites

  • 5 months later...

HI, for those who still interested in this topic.
This is my solution and it works fine for me (PS 1.6)
 

I changed this "generateReference" like this :
 

/**
* Gennerate a unique reference for orders generated with the same cart id
* This references, is usefull for check payment
*
* @return String
*/
public static function generateReference()
{
$OrderMaxID = Db::getInstance()->getValue('
SELECT MAX(id_order)
FROM '._DB_PREFIX_.'orders ');
 
return str_pad((int)$OrderMaxID+1, 9, "0", STR_PAD_LEFT);
// return strtoupper(Tools::passwdGen(9, 'NUMERIC'));
}
 
NOTA : the order reference will be incremented ;)
Edited by rachid.antipodes (see edit history)
Link to comment
Share on other sites

  • 2 months later...

Omdat de module Order referentie change niet meer werkt in versie 1..6.1.4

zelf maar wat gemaakt

 

Ga naar classes/order/order.php en zoek op generateReference en vervang de code door deze

 

 

public static function generateReference()
{
    $last_id = Db::getInstance()->getValue('
        SELECT MAX(id_order)
        FROM '._DB_PREFIX_.'orders');
    return str_pad((int)$last_id + 1, 8, 'NR-000000', STR_PAD_LEFT);
    }
 

Edited by Pietou (see edit history)
Link to comment
Share on other sites

  • 5 months later...

The above solutions are essentially correct, but you REALLY should refrain from modifying any of the core code if you can keep from it. I put all of my mods in a special folder locally after I apply any upgrades to prestashop or my theme engine, then I upload the modifications one by one (after each one is tested).

 

These instructions are for 1.6.x users - ONLY!

 

1) Create a file named order.php and place this code in that file

2) Next, upload the file to /override/classes/order/order.php

3) Navigate to the /cache folder and delete the file class_index.php (it will be recreated on the next page request)

<?php
/*
*  RETURN ORDER REFERENCE TO SEQUENTIAL NUMERIC VALUE
*
*  2016 PrestaShop v1.6.1.x
*  Override by obewanz
*
*  You can use the following SQL query to change the starting order no if desired
*  where the number 101 is the next desired order number:
*  ALTER TABLE `ps_orders` AUTO_INCREMENT = 101
*  --------------------------------------------
*  OPTION: (ALL NUMERIC)
*  str_pad((int)$last_id + 1, 9, '000000000', STR_PAD_LEFT);
*  OPTION SET TO ORIG 1.5.x STYLE REFERENCE NUMBERS: 
*  str_pad((int)$last_id + 1, 6, '000000', STR_PAD_LEFT);
*/

Class Order extends OrderCore
{
  public static function generateReference()
  {
    $last_id = Db::getInstance()->getValue('
        SELECT MAX(id_order)
        FROM '._DB_PREFIX_.'orders');
    return str_pad((int)$last_id + 1, 9, 'NR-000000', STR_PAD_LEFT);
  }
}

You should be finished now, and your next order will have a reference something like: NR-000101

 

The second "OPTION" in the code comments returns the order reference number to essentially that of PS 1.5.x -

I have also included the appropriate SQL statement in the code comments to set the next order number if needed.

 

PS: I posted a slightly different version of this in another thread, just can't find which one.

Edited by obewanz (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 10 months later...
  • 2 weeks later...

Do we have any solution for Prestashop 1.7 ?

Sorry Grubybarti, I have been unable to install a working version of 1.7 on any of my hosting accounts. I will eventually get around to getting 1.7 working somewhere, so will post a link or the compatible code for that here when it is done.

(Please note, PS 1.7 is LOW on my priority list at the moment - I don't mind being on the leading edge of certain technologies, but absolutely refuse to be on the bleeding edge... and with Prestashop's track record of every release breaking something in the prior release - you will absolutely bleed cash if you don't wait for the code to settle down, usually takes about 6 months to a year for these guys.)

Link to comment
Share on other sites

×
×
  • Create New...