16 hours ago, zod said:Thank you obewanz, instead of the Order ID, I changed SQL query to slightly improve your code, now it is counting the total orders of the current year. So it is a string like RO-2019/000001 and so on.
<?php class Order extends OrderCore { public static function generateReference() { $last_id = Db::getInstance()->getValue("SELECT count(`id_order`) FROM `ps_orders` WHERE `date_add` > '" . date('Y') . "-01-01'"); $next_id = (int)$last_id + 1; return "RO-".date('Y')."/".str_pad($next_id, 6, '0', STR_PAD_LEFT); } }Interesting take, I had thought of doing something similar, especially using count() instead of max(), but haven't really revisted the override since its original writing, until lately anyway. Did you by chance change the field length of the "reference" column in the table as well?
I have (finally) provided a new override to folkifoon to test to see if it fixes his problem. It modifies the paymentModuleCore so the value gets created and inserted during the validation part of the process, this is the only place I could find to make certain the reference number would be unique no matter what since it relies on the autonumber value created in the database for the sequential value.
453