How To Handle Tax Rate Changes In Magento

Germany decided to temporarily change the VAT from 19% to 16% and from 7% to 5% from July 2020 until the end of 2020 – this is the current plan at least. One big question for all shop owners is of course how they can change their tax rates on time. Our solution is a n98-magerun module for Magento 1 and a custom console command for Magento 2. Calling these via a cronjob should be enough to handle the tax rate change on time. Interested?

Magento 1: n98-magerun Module

We implemented a free, open source n98-magerun module, which lets you change your rates easily. You only need to export the IDs of the respective tax rates and put them into a comma-separated list. Then, you can change the rate of the tax rates with e.g. the IDs 1 and 2 to 16.00 % with the following command:

n98-magerun.phar tax:rates:edit --ids 1,2 --rate 16.00 --update-titles

The --update-titles option makes sure that your old rate – e.g. „19“ is replaced with the new rate „16“ in the code of the tax rate and all associated store-specific titles. It really just runs a basic str_replace, so do check if it works for you, but I think it should handle most cases correctly.

You can find more information in the respective GitHub repository.

Magento 2: Console Command

Since Magento 2 comes with a cool bin/magento CLI tool by default, there is no need to use magerun (although it has helpful additions!). We implemented a free, open source Magento module, which adds a CLI command that lets you change your rates easily. You can use it in exactly the same way as our M1 magerun module:

bin/magento tax:rates:edit --ids 1,2 --rate 16.00 --update-titles

You can find more information in the respective GitHub repository.

Cronjob / At

Via a cronjob, you can run anything at any specific point in time. To make sure the command, which changes your tax settings, runs at 0 o’clock on July 1st, simply add the following to your crontab:

0 0 1 7 * cd /path/to/your/shop && n98-magerun.phar tax:rates:edit --ids 1,2 --rate 16.00 --update-titles

This will run the command on July 1st. However, cronjobs are meant to be run on a regular basis. Hence, this command will be run on July 1st every year. So please make sure to remove the cronjob after it ran 🙂

Alternatively, you could use the at command.

Putting It All Together

Here is a checklist to follow for automating the tax changes on July 1st:

  1. Install our M1 magerun module / M2 module.
  2. Create a comma-separated list of tax rate IDs, which you need to update. One with the higher, one with the lower rates. Here is a simple SQL command, which should get you started for simple shops:
    SELECT GROUP_CONCAT(tax_calculation_rate_id) FROM tax_calculation_rate WHERE rate = 19.00;
  3. Add a cronjob, which runs our command at midnight on July 1st.
  4. Sit back and relax 😉

Other Solutions

I know of three other solutions, which you may want to consider as well. We did write our own, because none of the existing solutions really convinced us.

  1. Tax Switcher by Commercers (Magento 1, Magento 2): This extension lets you define – besides the default tax rules – temporary tax rules, which are only valid from and to a specific date.
  2. Magento Tax Changer by web-vision: This is – similar to our console command – also a quite technical solution. You call a script, which changes your settings. However, it uses custom database tables, raw SQL and simply replaces all rules with one rate to a new rate, which may be problematic if you only need to change some rates.
  3. TaxRatesManager by Yireo (Magento 1, Magento 2): This Magento extension can import tax rates automatically from a GitHub repository also maintained by Yireo, which will be updated with the new rates on July 1.

3 Gedanken zu „How To Handle Tax Rate Changes In Magento“

  1. Any ideas on how to cover already created orders. All of the tax related stuff is written into sales_flat_tables and therefor not affected by changes.
    This is relevant if between order and shipment/invoice the tax changes occur.

    1. Sorry, Nils, I somehow did not see any notification regarding this. Unfortunately, I do not have any helpful ideas regarding this anyway, sorry! I fear the only sane and non-hacky way is to cancel and re-create the order.

  2. Hallo Simon,

    wie schon im channel erwähnt, die Plugins laufen perfekt. Problem gab es nur durch unsaubere Datenbankeinträge.

    Zum Einen hatten wir (in einem Magento2-Shop) falsch gefüllte Datenbankspalten („“ statt „*“ in der Spalte tax_calculation_rate.tax_postcode).

    Zum Anderen hatten wir einen Shop (Magento1) mit doppelten TaxRate einträgen.

    Es ist zwar logisch, dass man die TaxRates nicht ändern kann, wenn man sie nicht speichern kann, aber vielleicht hilft es ja dem einen oder anderen, beim Test.

    Viele Grüße und Danke,

    Willi

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert