Fernando Posted April 13, 2020 Posted April 13, 2020 Hello, I would like to make my invoice numbers, to go up by two number each purchase. Meaning 000001 then 000003 then 000005 then 000007 Is this simple? Thank you for you help.
Rhapsody Posted April 13, 2020 Posted April 13, 2020 (edited) I believe you can create an override as override/classes/order/Order.php and change the increment value from 1 to 2 This code hasn't been verified but should be close to what you need. Edit: I verified this on a test shop and it works. <?php /******* * Override Created from Thirty Bees Order.php to increment invoice numbers by 2 * ****** */ class Order extends OrderCore { /** * @param int $orderInvoiceId * @param int $idShop * * @return bool * @throws PrestaShopException */ public static function setLastInvoiceNumber($orderInvoiceId, $idShop) { if (!$orderInvoiceId) { return false; } $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $idShop); // If invoice start number has been set, you clean the value of this configuration if ($number) { Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $idShop); } $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number ='; if ($number) { $sql .= (int) $number; } else { // Find the next number (***line below was + 1 changed to + 2 to increment by 2****) $newNumberSql = 'SELECT (MAX(`number`) + 2) AS new_number FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ? ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int) date('Y') : ''); $newNumber = DB::getInstance()->getValue($newNumberSql); $sql .= (int) $newNumber; } $sql .= ' WHERE `id_order_invoice` = '.(int) $orderInvoiceId; return Db::getInstance()->execute($sql); } } Edited April 13, 2020 by Rhapsody Tested
DRMasterChief Posted April 13, 2020 Posted April 13, 2020 Hi, you can use this module, works with tb: http://greenmousestudio.com/en/numeric-reference/
Rhapsody Posted April 13, 2020 Posted April 13, 2020 4 hours ago, DRMasterChief said: Hi, you can use this module, works with tb: http://greenmousestudio.com/en/numeric-reference/ It appears that is for order numbers, not the invoice numbers as the OP requested. A similar override can be done as the one above in Order.php if sequential order numbers are desired instead of the random letters.
PeterPan Posted January 17, 2023 Posted January 17, 2023 On 4/13/2020 at 3:23 PM, Rhapsody said: I believe you can create an override as override/classes/order/Order.php and change the increment value from 1 to 2 This code hasn't been verified but should be close to what you need. Edit: I verified this on a test shop and it works. <?php /******* * Override Created from Thirty Bees Order.php to increment invoice numbers by 2 * ****** */ class Order extends OrderCore { /** * @param int $orderInvoiceId * @param int $idShop * * @return bool * @throws PrestaShopException */ public static function setLastInvoiceNumber($orderInvoiceId, $idShop) { if (!$orderInvoiceId) { return false; } $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $idShop); // If invoice start number has been set, you clean the value of this configuration if ($number) { Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $idShop); } $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number ='; if ($number) { $sql .= (int) $number; } else { // Find the next number (***line below was + 1 changed to + 2 to increment by 2****) $newNumberSql = 'SELECT (MAX(`number`) + 2) AS new_number FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ? ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int) date('Y') : ''); $newNumber = DB::getInstance()->getValue($newNumberSql); $sql .= (int) $newNumber; } $sql .= ' WHERE `id_order_invoice` = '.(int) $orderInvoiceId; return Db::getInstance()->execute($sql); } } So I create a file named order.php put your code into this file and copied the file in folder ...override/classes/order/ doesn´t work. any idea?
e-com Posted January 17, 2023 Posted January 17, 2023 Not order.php but Order.php After adding override file, delete the /cache/class_index.php file 1
PeterPan Posted January 17, 2023 Posted January 17, 2023 1 hour ago, e-com said: Not order.php but Order.php After adding override file, delete the /cache/class_index.php file thanks, that´s the solution 🙂
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now