Taxation
Sylius has a flexible taxation system that allows you to apply taxes based on different products, billing zones, and custom tax calculators. Let’s break it down.
Tax Categories
To handle taxes in Sylius, you need at least one Tax Category. Tax Category groups products with the same tax rate.
If all your products are taxed the same, create a simple category like "Taxable Goods." If you have products with different tax rates (like clothing, books, or food), create separate categories for each.
Additionally, you can create zones to apply the correct tax rates for customers from different countries.
How to Create a Tax Category Programmatically
Now you have a new Tax Category.
Setting a Tax Category on a Product Variant
To calculate taxes for products, each ProductVariant needs a Tax Category.
Tax Rates
A Tax Rate is the percentage applied to the product price. Tax Rates include details like:
Whether it is included in the product's price
The applicable zone (country or region)
The associated tax category
The calculator used to compute the tax
Tax Rates and Price Inclusion
Included in Price: when taxes are included, the final price will include the tax amount.
Example: A 23% VAT on a $10 product will result in a final price of $10, with $1.87 in taxes included.
Excluded from Price: when taxes are excluded, the tax is added to the order total at checkout.
Example: A 23% VAT on a $10 product will result in a final price of $12.30, with $2.30 in taxes added at checkout.
How to Create a Tax Rate Programmatically
Before creating a tax rate, make sure you understand how zones work (see the Zones chapter).
Default Tax Zone
When a customer hasn’t provided an address, Sylius uses the default tax zone assigned to the channel to estimate taxes. This allows prices to include taxes even when the customer’s location isn’t known.
Applying Taxes
Sylius applies taxes during checkout using the OrderTaxesProcessor. This processor calculates the correct taxes based on the products in the cart, the customer’s zone, and the applicable tax rates.
Tax Calculators
Sylius uses calculators to compute taxes. The calculator type is determined by the TaxRate assigned to each product. Sylius provides built-in calculators, but you can also create custom ones.
Built-in Calculators:
DefaultCalculator: Calculates taxes with rounding.
DecimalCalculator: Calculates taxes without rounding, distributing decimals among items.
Creating a Custom Tax Calculator
To create a custom calculator:
Implement the
CalculatorInterface
.Register it as a service and tag it with
sylius.tax_calculator
.
Example:
Register it:
Last updated