New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tax zones leading to bad tax calculation #11788
Comments
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions. |
Do not stale. This is still an issue, and can till lead to some errors in taxes. |
Applying more than one tax will lead to more issues. Also having more than one zone in the match fixes the issue we have. I think adding a priority to the Tax rates could help fixe the side effect of the first fix. So, what I suggest:
@Sylius/core-team We need to discuss this, there is a big issue here and I am very surprised than nobody complained about it. |
Or we can say that an item (product or shipping) can have only one "tax included in the price" applied. |
The snippet above correct the missing zones tax application but we can have some weird cases. diff --git a/src/Sylius/Component/Core/OrderProcessing/OrderTaxesProcessor.php b/src/Sylius/Component/Core/OrderProcessing/OrderTaxesProcessor.php
index a39978abb4..52147c925e 100644
--- a/src/Sylius/Component/Core/OrderProcessing/OrderTaxesProcessor.php
+++ b/src/Sylius/Component/Core/OrderProcessing/OrderTaxesProcessor.php
@@ -58,34 +58,40 @@ final class OrderTaxesProcessor implements OrderProcessorInterface
return;
}
- $zone = $this->getTaxZone($order);
+ $zones = $this->getTaxZones($order);
- if (null === $zone) {
+ if (null === $zones) {
return;
}
+ $strategyApplied = false;
/** @var TaxCalculationStrategyInterface $strategy */
foreach ($this->strategyRegistry->all() as $strategy) {
- if ($strategy->supports($order, $zone)) {
- $strategy->applyTaxes($order, $zone);
-
- return;
+ foreach ($zones as $zone) {
+ if ($strategy->supports($order, $zone)) {
+ $strategy->applyTaxes($order, $zone);
+ $strategyApplied = true;
+ }
}
}
- throw new UnsupportedTaxCalculationStrategyException();
+ if (!$strategyApplied) {
+ throw new UnsupportedTaxCalculationStrategyException();
+ }
}
- private function getTaxZone(OrderInterface $order): ?ZoneInterface
+ private function getTaxZones(OrderInterface $order): ?array
{
$billingAddress = $order->getBillingAddress();
- $zone = null;
+ $zones = null;
if (null !== $billingAddress) {
- $zone = $this->zoneMatcher->match($billingAddress, Scope::TAX);
+ $zones = $this->zoneMatcher->matchAll($billingAddress, Scope::TAX);
}
- return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
+ $defaultTaxZone = $this->defaultTaxZoneProvider->getZone($order);
+
+ return $zones ?: ($defaultTaxZone ? [$defaultTaxZone] : null) ;
}
private function clearTaxes(OrderInterface $order): void |
Sylius version affected: all since we have the tax zones I think
Description
Considering a country (let's say FRANCE) is in two zones (let's say ZONE A and then ZONE B, both type "country" so same priority, but A entered before B in database).
Considering a tax rate for ZONE A.
If I order with a billing address in FRANCE, then I don't get the tax, but I should because FRANCE is in ZONE A.
BUT !
Sylius/src/Sylius/Component/Addressing/Matcher/ZoneMatcher.php
Lines 41 to 59 in 7bdc5d4
Here we take the last zone in the loop (line 46), which will lead to ZONE B.
And since ZONE B ≠ ZONE A (zone with the tax applied) then I won't have any tax applied.
The issue here is: we consider a country to be in ONE zone, but it can be in more than one zone.
Steps to reproduce
Add the ZONE A and ZONE B for the following countries: FRANCE. Add them in this order so ZONE B is the last one taken into account in the
ZoneMatcher
.Add a tax rate applying on ZONE A.
Order something with FRANCE as billing country.
You won't have any tax, but you SHOULD.
Possible Solution
I think it's important to consider that a country can be in more than one zone and to compare all zones to the tax rates, instead of only one.
The text was updated successfully, but these errors were encountered: