Replace Order References with IDs in PrestaShop

If you find it annoying to have Order References with random characters, here is how to take Order IDs back in Prestashop, for customers as well.

Watch the Screencast

Text Version

There is just one quick step to take, in order to replace the new odd reference number, and that is amending the generateReference method of the Order class.

Let’s create an override for it! Create a new file inside override/classes/order and name it Order.php.
Add the usual override code inside:

[php]
Class Order extends OrderCore
{

}
[/php]

Then, inside it, let’s paste the generateReference method:

[php]
public static function generateReference()
{
return strtoupper(Tools::passwdGen(9, ‘NO_NUMERIC’));
}
[/php]

We want to grab the very last order ID, then increase it by one, increase it by one and pad it so all the new references have the same length in terms of characters

[php]
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, ‘000000000’, STR_PAD_LEFT);

}
[/php]

Need PrestaShop Modules? Have a look at my Prestashop Addons Store!

Looking for quality PrestaShop Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , | Posted under PrestaShop | RSS 2.0

Author Spotlight

Fabio Porta

Fabio has been involved in web development and design since 2005, when launched his first website at the age of 16. He’s now highly skilled in both client and server side development, along with design, and since August 2012 runs a successful website about PrestaShop tutorials and Prestashop Modules called Nemo’s Post Scriptum, at http://nemops.com

Leave a Reply

Your email address will not be published. Required fields are marked *