Jump to content
thirty bees forum

Recommended Posts

Posted

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.

Posted (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 by Rhapsody
Tested
  • 2 years later...
Posted
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?

Posted
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 🙂

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...