From 05896b9d53cc4db24670e3414082aa399e36ba97 Mon Sep 17 00:00:00 2001 From: Arnaud Hours Date: Tue, 3 Mar 2026 14:41:32 +0100 Subject: [PATCH 1/2] fix(import): fix configuration causing tax calculation issue --- Model/Import/Importorder.php | 8 ++------ Model/Import/Quote.php | 10 +++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Model/Import/Importorder.php b/Model/Import/Importorder.php index 1ec4fa1..cd69941 100644 --- a/Model/Import/Importorder.php +++ b/Model/Import/Importorder.php @@ -1445,13 +1445,9 @@ private function createQuote(MagentoCustomer $customer, array $products): Quote ->setSameAsBilling(0); $quote->assignCustomerWithAddressChange($customerRepo, $billingAddress, $shippingAddress); // check if store include tax (Product and shipping cost) - $priceIncludeTax = ($this->taxConfig->priceIncludesTax($quote->getStore()) - && $this->taxConfig->displayCartPricesInclTax($quote->getStore()) - && $this->taxConfig->displaySalesPricesInclTax($quote->getStore())); + $priceIncludeTax = $this->taxConfig->priceIncludesTax($quote->getStore()); + $shippingIncludeTax = $this->taxConfig->shippingPriceIncludesTax($quote->getStore()); - $shippingIncludeTax = ($this->taxConfig->shippingPriceIncludesTax($quote->getStore()) - && $this->taxConfig->displayCartShippingInclTax($quote->getStore()) - && $this->taxConfig->displaySalesShippingInclTax($quote->getStore())); // if this order is b2b if ((int) $this->backendSession->getIsLengowB2b() === 1) { $priceIncludeTax = true; diff --git a/Model/Import/Quote.php b/Model/Import/Quote.php index 819c1c3..fd44dac 100644 --- a/Model/Import/Quote.php +++ b/Model/Import/Quote.php @@ -244,11 +244,15 @@ public function addLengowProducts($products, bool $priceIncludeTax = true): Quot $priceProduct = $product['price_unit'] ?? 0.0; $tax = $product['tax_unit'] ?? 0.0; if (!$priceIncludeTax) { - $taxRate = $this->taxCalculation->getCalculatedRate( - $magentoProduct->getTaxClassId(), - $this->getCustomer()->getId(), + $taxRequest = $this->calculation->getRateRequest( + $this->getShippingAddress(), + $this->getBillingAddress(), + $this->getCustomerTaxClassId(), $this->getStore() ); + $taxRequest->setProductClassId($magentoProduct->getTaxClassId()); + $taxRate = $this->calculation->getRate($taxRequest); + $tax = $this->calculation->calcTaxAmount($priceProduct, $taxRate, true); } From b461ddd6604c138c4df11f98cbcc0a1532d75232 Mon Sep 17 00:00:00 2001 From: Arnaud Hours Date: Fri, 20 Mar 2026 15:56:48 +0100 Subject: [PATCH 2/2] fix(import): fix shipping tax double-taxation on orders with non-zero shipping Marketplace shipping costs are always TTC (tax-inclusive). Magento's setShippingPrice/updateRates treats shipping rates as excl-tax internally and adds tax on top. Previously, the shippingIncludeTax config check was always false (due to display config AND conditions), so tax was always extracted before setting the shipping price. After simplifying the check, shippingIncludeTax became true, skipping extraction and causing Magento to add tax on top of an already-TTC amount (double-taxation). Fix: always extract shipping tax using address-based getRateRequest (consistent with the product tax fix in Quote.php), since marketplace shipping is always TTC regardless of Magento's config. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Model/Import/Importorder.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Model/Import/Importorder.php b/Model/Import/Importorder.php index cd69941..c04ab72 100644 --- a/Model/Import/Importorder.php +++ b/Model/Import/Importorder.php @@ -1444,33 +1444,35 @@ private function createQuote(MagentoCustomer $customer, array $products): Quote ->setSaveInAddressBook(0) ->setSameAsBilling(0); $quote->assignCustomerWithAddressChange($customerRepo, $billingAddress, $shippingAddress); - // check if store include tax (Product and shipping cost) + // check if store include tax (Product prices) $priceIncludeTax = $this->taxConfig->priceIncludesTax($quote->getStore()); - $shippingIncludeTax = $this->taxConfig->shippingPriceIncludesTax($quote->getStore()); // if this order is b2b if ((int) $this->backendSession->getIsLengowB2b() === 1) { $priceIncludeTax = true; - $shippingIncludeTax = true; } // add product in quote $quote->addLengowProducts($products, $priceIncludeTax); // get shipping cost with tax $shippingCost = $this->processingFee + $this->shippingCost; $taxShippingCost = 0.0; - // if shipping cost not include tax -> get shipping cost without tax - if (!$shippingIncludeTax) { + // marketplace shipping is always TTC (tax-inclusive) + // Magento shipping rates are always treated as excl-tax internally, + // so we must always extract tax to get the correct base amount + if ($shippingCost > 0) { $shippingTaxClass = $this->scopeConfig->getValue( TaxConfig::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $quote->getStore()->getWebsiteId() ); - - $taxRate = $this->taxCalculation->getCalculatedRate( - $shippingTaxClass, - $customer->getId(), - $currentStore->getId() + $taxRequest = $this->calculation->getRateRequest( + $quote->getShippingAddress(), + $quote->getBillingAddress(), + $quote->getCustomerTaxClassId(), + $quote->getStore() ); + $taxRequest->setProductClassId($shippingTaxClass); + $taxRate = $this->calculation->getRate($taxRequest); $taxShippingCost = $this->calculation->calcTaxAmount($shippingCost, $taxRate, true); } $shippingCost -= $taxShippingCost;