-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #12731 Add cookbook with how to change tax address (arti0090)
This PR was merged into the 1.9 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.9 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | same as #12724 but on 1.9 branch | License | MIT Opened new PR as old one was making a lot of merge conflicts. Commits ------- 934749e Add cookbook with how to change tax address
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
How to configure tax rates to be based on shipping address? | ||
=========================================================== | ||
|
||
The default configuration of Sylius tax calculation is based on billing address but there are situations where we would | ||
like to use a shipping address to be used in this process. This may be useful to anyone who uses Sylius in European Union | ||
as from 1st July 2021 the new taxation rules will be applied. | ||
|
||
.. note:: | ||
|
||
You can learn more about new EU taxation rules `here <https://ec.europa.eu/taxation_customs/business/vat/modernising-vat-cross-border-ecommerce_en>`_. | ||
|
||
To change the way how the taxes are calculated; by billing or by shipping address, you need to override the service called | ||
``OrderTaxesProcessor.php`` from ``Sylius/Component/Core/OrderProcessing``. | ||
|
||
First let's copy code from original Processor to our service | ||
from ``%kernel.project_dir%/vendor/sylius/sylius/src/Sylius/Component/Core/OrderProcessing/OrderTaxesProcessor.php`` to ``src/OrderProcessing/OrderTaxesProcessor.php`` | ||
|
||
Then register our new service: | ||
|
||
.. code-block:: yaml | ||
# app/config/services.yaml | ||
App\OrderProcessing\OrderTaxesProcessor: | ||
arguments: | ||
- '@sylius.provider.channel_based_default_zone_provider' | ||
- '@sylius.zone_matcher' | ||
- '@sylius.registry.tax_calculation_strategy' | ||
tags: | ||
- { name: sylius.order_processor, priority: 10 } | ||
Now we need to change the method ``getTaxZone`` to be using the shipping address: | ||
|
||
.. code-block:: php | ||
//... | ||
private function getTaxZone(OrderInterface $order): ?ZoneInterface | ||
{ | ||
$shippingAddress = $order->getShippingAddress(); | ||
$zone = null; | ||
if (null !== $shippingAddress) { | ||
$zone = $this->zoneMatcher->match($shippingAddress, Scope::TAX); | ||
} | ||
return $zone ?: $this->defaultTaxZoneProvider->getZone($order); | ||
} | ||
//... | ||
And with this change, the way how taxes are calculated will be based on shipping address. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* :doc:`/cookbook/taxation/customize-tax-by-address` |