Need to change order numbering and invoice numbering?
There is a script that works like this:
1) Take the last two digits of the year + add the last highest number + add 1
2) if the year changes, the numbering is automatically reset from 1
3) The file is named Order.php and is placed in the prestashop root/override/classes/order folder
I hope this helps a lot of people.
Prestashop compatibility: 1.5, 1.6, 1.7
<?php Class Order extends OrderCore { public static function generateReference() { $curYear = substr(date('Y'),2,2); $last_id = Db::getInstance()->getValue(' SELECT MAX(id_order) FROM `'._DB_PREFIX_.'orders`'); return $curYear.sprintf('%04d',(int)$last_id + 1); } public static function setLastInvoiceNumber($order_invoice_id, $id_shop) { if (!$order_invoice_id) { return false; } $curYear2 = substr(date('Y'),2,2); $last_id2 = Db::getInstance()->getValue(' SELECT MAX(number) FROM `'._DB_PREFIX_.'order_invoice`'); $number1 = sprintf('%04d',(int)$last_id2 + 1); if (substr($number1,0,2) == $curYear2) { $newInvoiceNumber = $number1; } else { $newInvoiceNumber = $curYear2.sprintf('%04d', (int)$last_id2 + 1); } $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number = '.$newInvoiceNumber.' WHERE `id_order_invoice` = '.(int)$order_invoice_id; return Db::getInstance()->execute($sql); } }