gewebe/sylius-vat-plugin

Sylius VAT number and tax calculation plugin

Installs: 166

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 3

Forks: 0

Open Issues: 0

Type:sylius-plugin


README

Latest Version on Packagist Software License Quality Score

Features

  • Installer for EU countries, zones and VAT rates configuration
  • VAT number field at Address entity
  • Validate VAT numbers (by country, format and existence)
  • Placing an order with 0% VAT if
    • Customers billing country is different from shop billing data
    • VAT number validation was successful

Installation

Download the plugin via composer

composer require gewebe/sylius-vat-plugin

Enable the plugin

Register the plugin by adding it to your config/bundles.php file

<?php

return [
    // ...
    Gewebe\SyliusVATPlugin\GewebeSyliusVATPlugin::class => ['all' => true],
];

Configure the plugin

# config/packages/gewebe_sylius_vat_plugin.yaml

imports:
    - { resource: '@GewebeSyliusVATPlugin/Resources/config/app/config.yml'}

Copy templates

Copy customized templates to your templates directory (e.g templates/bundles/):

mkdir -p templates/bundles/SyliusAdminBundle/
cp -R vendor/gewebe/sylius-vat-plugin/src/Resources/views/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/
mkdir -p templates/bundles/SyliusShopBundle/
cp -R vendor/gewebe/sylius-vat-plugin/src/Resources/views/SyliusShopBundle/* templates/bundles/SyliusShopBundle/

Extend Address entity

  • If you use annotations mapping:
# src/Entity/Addressing/Address.php

namespace App\Entity\Addressing;

use Doctrine\ORM\Mapping as ORM;
use Gewebe\SyliusVATPlugin\Entity\VatNumberAddressInterface;
use Gewebe\SyliusVATPlugin\Entity\VatNumberAwareTrait;
use Sylius\Component\Core\Model\Address as BaseAddress;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_address")
 */
class Address extends BaseAddress implements VatNumberAddressInterface
{
    use VatNumberAwareTrait;
  • If you use yaml mapping add also:
# config/doctrine/Address.orm.yaml

App\Entity\Addressing\Address:
    type: entity
    table: sylius_address
    fields:
        vatNumber:
            type: string
            column: vat_number
            nullable: true
        vatValid:
            type: boolean
            column: vat_valid
        vatValidatedAt:
            type: datetime
            column: vat_validated_at
            nullable: true

Update your database schema

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

Usage

Install EU countries and VAT rates

# EU VAT on digital services (MOSS scheme)
bin/console vat:install:eu

# EU with French VAT (cross-border)
bin/console vat:install:eu FR

# EU with French VAT and passed threshold in Spain and Portugal (cross-border)
bin/console vat:install:eu FR -t ES,PT

# EU with French VAT included in price
bin/console vat:install:eu FR -i

# EU with German standard and reduced VAT categories
bin/console vat:install:eu DE -c standard,reduced

Validate customers VAT number

1. Create new order with VAT number at shipping address

Screenshot checkout address with vat number

2. Show VAT number and validation status at admin orders

Screenshot order shipping address with vat number

Testing

Setup

$ composer install
$ cd tests/Application
$ yarn install
$ yarn run gulp
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ symfony server:start --port=8080 --dir=public

Run Tests

$ vendor/bin/behat
$ vendor/bin/phpspec run
$ vendor/bin/phpstan analyse -c phpstan.neon -l max src/
$ vendor/bin/psalm