
Quick Tip: 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:
Class Order extends OrderCore { }
Then, inside it, let’s paste the generateReference method:
public static function generateReference() { return strtoupper(Tools::passwdGen(9, 'NO_NUMERIC')); }
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
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); }