Skip to content

Commit

Permalink
Add cookbook with how to customize taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Jun 21, 2021
1 parent a983c58 commit 902eb60
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions docs/cookbook/taxation/customize-tax-by-address.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,45 @@ as from 1st July 2021 the new taxation rules will be applied.

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, we have prepared a simple parameter
that you need to change `sylius_core.taxation.default_strategy` in your configs:
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`

.. code-block:: php
<?php
//...
final class OrderTaxesProcessor implements OrderProcessorInterface
{
//...
Then register our new service:

.. code-block:: yaml
# app/config/config.yml
parameters:
sylius_core.taxation.default_strategy: false
# 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 line `$billingAddress = $order->getBillingAddress()` to:

.. code-block:: php
//...
private function getTaxZone(OrderInterface $order): ?ZoneInterface
{
$billingAddress = $order->getShippingAddress();
$zone = null;
//...
And with this change, the way how taxes are calculated is based on shipping address.
And with this change, the way how taxes are calculated will be based on shipping address.

0 comments on commit 902eb60

Please sign in to comment.