Eutanasio Posted March 28, 2022 Share Posted March 28, 2022 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 More sharing options...
knacky Posted March 29, 2022 Share Posted March 29, 2022 Prestashop version ? Link to comment Share on other sites More sharing options...
Eutanasio Posted March 29, 2022 Author Share Posted March 29, 2022 5 hours ago, knacky said: Prestashop version ? 1.7.6 Link to comment Share on other sites More sharing options...
knacky Posted March 29, 2022 Share Posted March 29, 2022 You are already solving it here: https://github.com/PrestaShop/PrestaShop/issues/28056 Link to comment Share on other sites More sharing options...
Eutanasio Posted March 29, 2022 Author Share Posted March 29, 2022 18 minutes ago, knacky said: You are already solving it here: https://github.com/PrestaShop/PrestaShop/issues/28056 trying to, but I find this forum normally of much help, in Github they'll just close the post as they can't replicate and don't consider it to be a bug Link to comment Share on other sites More sharing options...
knacky Posted March 29, 2022 Share Posted March 29, 2022 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 More sharing options...
Eutanasio Posted March 29, 2022 Author Share Posted March 29, 2022 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 More sharing options...
knacky Posted March 29, 2022 Share Posted March 29, 2022 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 More sharing options...
Eutanasio Posted March 30, 2022 Author Share Posted March 30, 2022 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 More sharing options...
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