Jump to content

How to make PS to write taxes in the table order_detail_tax?


Eutanasio

Recommended Posts

Hi,

I don't know why, despite having all taxes and invoicing settings well configured, I'm not getting PS to record the taxes of the orders in table order_detail_tax.

When we place an order FO or BO, everything's fine, even customer can check the order details and see the taxes in the FO, but this info is not being saved in table order_detail_tax. I need this as another module reads the tax info of the orders from that table.

Thanks for the help

Link to comment
Share on other sites

OrderDetail.php

Function saveTaxCalculator

/**

* Save the tax calculator.

*

* @since 1.5.0.1

* @deprecated Functionality moved to Order::updateOrderDetailTax

* because we need the full order object to do a good job here.

* Will no longer be supported after 1.6.1

* (Note: this one is not that deprecated because Order::updateOrderDetailTax

* performs no update unless order_detail_tax is filled. So we rely on updateTaxAmount

* which correctly builds the TaxCalculator with up to date taxes unlike getTaxCalculatorStatic)

*

* @return bool

*/

Link to comment
Share on other sites

5 minutes ago, knacky said:

OrderDetail.php

Function saveTaxCalculator

/**

* Save the tax calculator.

*

* @since 1.5.0.1

* @deprecated Functionality moved to Order::updateOrderDetailTax

* because we need the full order object to do a good job here.

* Will no longer be supported after 1.6.1

* (Note: this one is not that deprecated because Order::updateOrderDetailTax

* performs no update unless order_detail_tax is filled. So we rely on updateTaxAmount

* which correctly builds the TaxCalculator with up to date taxes unlike getTaxCalculatorStatic)

*

* @return bool

*/

Thanks for the research, but I don't see the answer to my issue here. I see that the Function saveTaxCalculatorhas changed since 1.6.1 and moved to Order::updateOrderDetailTax. is this a new class where it's done? but what triggerst that action? maybe there's nothing wrong with the code itself, but anything regarding an exact configuration on Prestashop to properly record info about order's taxes in that specific table?

Thanks

Link to comment
Share on other sites

This is the answer that shows the function that records.
So, if it doesn't work, you have a rewritten override, or some module that blocks that function.
Only you can see what is happening in your e-shop, what you have installed, what you have modified.
There is no error in Prestashop, I have a clean installation and the write from the ps_order_detail_tax table is written correctly.

Link to comment
Share on other sites

On 3/29/2022 at 12:32 PM, knacky said:

This is the answer that shows the function that records.
So, if it doesn't work, you have a rewritten override, or some module that blocks that function.
Only you can see what is happening in your e-shop, what you have installed, what you have modified.
There is no error in Prestashop, I have a clean installation and the write from the ps_order_detail_tax table is written correctly.

Thanks for your answer, I was trying these days to understand all this. This is the piece of code I have in OrderDetail.php regarding the function you said, does it look good to you?

    /**
     * Save the tax calculator.
     *
     * @since 1.5.0.1
     * @deprecated Functionality moved to Order::updateOrderDetailTax
     *             because we need the full order object to do a good job here.
     *             Will no longer be supported after 1.6.1
     *
     * @return bool
     */
    public function saveTaxCalculator(Order $order, $replace = false)
    {
        // Nothing to save
        if ($this->tax_calculator == null) {
            return true;
        }

        if (!($this->tax_calculator instanceof TaxCalculator)) {
            return false;
        }

        if (count($this->tax_calculator->taxes) == 0) {
            return true;
        }

        if ($order->total_products <= 0) {
            return true;
        }

        $shipping_tax_amount = 0;

        foreach ($order->getCartRules() as $cart_rule) {
            if ($cart_rule['free_shipping']) {
                $shipping_tax_amount = $order->total_shipping_tax_excl;

                break;
            }
        }

        $ratio = $this->unit_price_tax_excl / $order->total_products;
        $order_reduction_amount = ($order->total_discounts_tax_excl - $shipping_tax_amount) * $ratio;
        $discounted_price_tax_excl = $this->unit_price_tax_excl - $order_reduction_amount;

        $values = '';
        foreach ($this->tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $amount) {
            switch (Configuration::get('PS_ROUND_TYPE')) {
                case Order::ROUND_ITEM:
                    $unit_amount = (float) Tools::ps_round($amount, _PS_PRICE_COMPUTE_PRECISION_);
                    $total_amount = $unit_amount * $this->product_quantity;

                    break;
                case Order::ROUND_LINE:
                    $unit_amount = $amount;
                    $total_amount = Tools::ps_round($unit_amount * $this->product_quantity, _PS_PRICE_COMPUTE_PRECISION_);

                    break;
                case Order::ROUND_TOTAL:
                    $unit_amount = $amount;
                    $total_amount = $unit_amount * $this->product_quantity;

                    break;
            }

            $values .= '(' . (int) $this->id . ',' . (int) $id_tax . ',' . (float) $unit_amount . ',' . (float) $total_amount . '),';
        }

        if ($replace) {
            Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'order_detail_tax` WHERE id_order_detail=' . (int) $this->id);
        }

        $values = rtrim($values, ',');
        $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount)
                VALUES ' . $values;

        return Db::getInstance()->execute($sql);
    }

 

Link to comment
Share on other sites

  • 2 years later...

HEllo,

this is kind of driving me crazy. I have nothing in table order_detail_tax.

keeping the thread above I have checked :

Order::updateOrderDetailTax

this is calling 

Order getProductTaxesDetails 

this is calling 

OrderDetail::getTaxCalculatorStatic($id_order_detail);

and this last one , guess what ? is doing a select from where ? 

        $sql = 'SELECT t.*, d.`tax_computation_method`
                FROM `' . _DB_PREFIX_ . 'order_detail_tax` t
                LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` d ON (d.`id_order_detail` = t.`id_order_detail`)
                WHERE d.`id_order_detail` = ' . (int) $id_order_detail;

From order_detail_tax that's empty !!

REally don't know how to fix. 

Daniel

Link to comment
Share on other sites

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...