Sylius plugin which allows Italian merchants to collect invoice data for their orders such as tax code, VAT number, SDI code, etc... as well as allowing the merchant to only apply taxes to those customers that can (and must) pay taxes in advance.
-
This plugin requires the MyOnlineStore/ViesBundle but this is not actually compatible with Symfony 7, there is an open PR: MyOnlineStore/ViesBundle#18
Thus, you have to run the following command to require a fork of the bundle which is compatible with Symfony 7:
composer config repositories.sandwich/vies-bundle git https://github.com/mmenozzi/ViesBundle.git
and you have to run this command too to allow "dev" versions of the bundle (we need the "dev-patch-1" version):
composer config minimum-stability dev
-
Require the plugin:
composer require webgriffe/sylius-italian-invoiceable-order-plugin
-
If they have not been added automatically, you have to add these bundles to
config/bundles.phpfile:Sandwich\ViesBundle\SandwichViesBundle::class => ['all' => true], Webgriffe\SyliusItalianInvoiceableOrderPlugin\WebgriffeSyliusItalianInvoiceableOrderPlugin::class => ['all' => true],
-
Configure your ActiveCampaign API connection parameters by creating the
config/packages/webgriffe_sylius_italian_invoiceable_order_plugin.yamlfile with the following content:imports: - { resource: "@WebgriffeSyliusItalianInvoiceableOrderPlugin/config/config.yaml" }
-
By default, the parameter
app.taxation.eu_zone_codeis set to "EU", as it must be the code of a zone representing the EU. This is used to determine if an order is invoiced to a company within the EU or not. Please change this parameter according to your Sylius's zone configuration if needed:# config/services.yaml parameters: app.taxation.eu_zone_code: 'EU' # Change it if needed
-
Your
Addressentity must implement theWebgriffe\SyliusItalianInvoiceableOrderPlugin\Model\ItalianInvoiceableAddressInterfaceand theSymfony\Component\Validator\GroupSequenceProviderInterface. You can use theWebgriffe\SyliusItalianInvoiceableOrderPlugin\Model\ItalianInvoiceableAddressTraitas implementation for both interfaces. -
Your
Orderentity must implement theWebgriffe\SyliusItalianInvoiceableOrderPlugin\Model\ItalianInvoiceableOrderInterface. You can use theWebgriffe\SyliusItalianInvoiceableOrderPlugin\Model\ItalianInvoiceableOrderTraitas default implementation for the interface. -
You need to import the
AddressandOrdervalidator configuration into your project by copying the configuration files provided by this plugin:mkdir -p config/validator/ cp vendor/webgriffe/sylius-italian-invoiceable-order-plugin/tests/TestApplication/config/validation/Address.xml config/validator/ cp vendor/webgriffe/sylius-italian-invoiceable-order-plugin/tests/TestApplication/config/validation/Order.xml config/validator/
WAIT! We are not done with this step yet. You must edit these files to change the namespace
Tests\Webgriffe\SyliusItalianInvoiceableOrderPluginto your own project namespace: there are 3 references that you have to change among these files.If you have the "App" as the base namespace of your app, this command should be enough:
Linux:
sed -i 's/Tests\\Webgriffe\\SyliusItalianInvoiceableOrderPlugin/App/g' config/validator/Address.xml config/validator/Order.xmlMacOS:
sed -i '' 's/Tests\\Webgriffe\\SyliusItalianInvoiceableOrderPlugin/App/g' config/validator/Address.xml config/validator/Order.xml
If you alread have some validator file for these entities you have to merge the configuration manually.
-
Configure Sylius to use the
Italian tax calculationtax calculation strategy. -
To properly enable group sequence validation of your Address entity you must set the
Defaultvalidation group instead of thesyliusvalidation group:# config/parameters.yaml parameters: # ... sylius.form.type.address.validation_groups: ['Default']
For more information see here.
-
Run migration
bin/console cache:clear bin/console doctrine:migrations:migrate
-
Add invoiceable fields to the address show template for admin. To do so you have to override this template:
vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/templates/shared/helper/address.html.twig
by copying directly our implementation provided in the plugin:
mkdir -p templates/bundles/SyliusAdminBundle/shared/helper/ cp vendor/webgriffe/sylius-italian-invoiceable-order-plugin/tests/TestApplication/templates/bundles/SyliusAdminBundle/shared/helper/address.html.twig templates/bundles/SyliusAdminBundle/shared/helper/address.html.twig
or by copying the original template and adding the invoiceable fields by yourself. In this case your template should look like the following:
{% macro address(address) %} <address> {% include '@WebgriffeSyliusItalianInvoiceableOrderPlugin/shared/address/billingAddressInfo.html.twig' with { address } only %} {{ address.phoneNumber }}<br/> {{ address.street }}<br/> {{ address.city }}<br/> {% if address|sylius_province_name is not empty %} {{ address|sylius_province_name }}<br/> {% endif %} {{ address.countryCode|sylius_country_name|upper }} {{ address.postcode }} </address> {% endmacro %}
Once installed this plugin will allow the users of the shop to enter all the invoicing information needed by an Italian company to properly invoice the order. In addition, this plugin checks the billing data of the order and uses them to decide whether the customer has to pay taxes or not.
This plugin will add the following fields to your address form:
- Billing recipient type, which allows the user to specify if the billing address is for a company or for an individual. This field will be required for every address used as the billing address for an order.
- Tax code, which in Italy is known as "Codice Fiscale". It's, more or less, like the social security number (SSN) in the US but in Italy both companies and individuals have a tax code. This field will be required for Italian individuals and companies and validated according the proper checksum algorithm.
- VAT Number, which in Italy is known as "Partita IVA". It's another identification number but for companies only not only in Italy but also in the EU. This field will be required for Italian companies and validated according the proper checksum algorithm. This field will be also required for EU companies and validated using the EU's VIES service using the MyOnlineStore/ViesBundle.
- SDI Code, where SDI stands for "Sistema Di Interscambio". It's a code that is needed to be able to properly generate an "electronic invoice" which is mandatory in Italy since January the 1st of 2019. This field will be required for Italian companies and validated according the proper rules of the Italian IRS (called "Agenzia delle Entrate" in Italy).
- PEC address, where PEC stands for "Posta Elettronica Certificata" (the Italian translation of "certified email"). It's like an email address but for a special email type meant to provide a legal equivalent of the traditional mail. See here for more information. This field will not be required even for Italian companies, but if entered it must be a valid email address.
This plugin will also require the Sylius's company field to be populated if the billing recipient type is set to company.
This plugin also replaces the Sylius's Sylius\Component\Addressing\Comparator\AddressComparatorInterface implementation by decorating it and by comparing also invoiceable fields. So different invoiceable address information provided during checkout are saved in the customer address book as new addresses.
This plugin also allows to select an invoiceable address from the address book in the checkout and properly fill the address form with all the invoicing information.
To contribute you need to:
-
Clone this repository into you development environment and go to the plugin's root directory,
-
Then, from the plugin's root directory, run the following commands:
composer install
-
Copy
tests/TestApplication/.envintests/TestApplication/.env.localand set configuration specific for your development environment. -
Link node_modules:
ln -s vendor/sylius/test-application/node_modules node_modules
-
Run docker (create a
compose.override.ymlif you need to customize services):docker-compose up -d
-
Then, from the plugin's root directory, run the following commands:
composer test-app-init
-
Run your local server:
symfony server:ca:install symfony server:start -d
-
Now at http://localhost:8080/ you have a full Sylius testing application which runs the plugin
After your changes you must ensure that the tests are still passing.
First setup your test database:
APP_ENV=test vendor/bin/console doctrine:database:create
APP_ENV=test vendor/bin/console doctrine:migrations:migrate -n
# Optionally load data fixtures
APP_ENV=test vendor/bin/console sylius:fixtures:load -nAnd build assets:
(cd vendor/sylius/test-application && yarn install)
(cd vendor/sylius/test-application && yarn build)
vendor/bin/console assets:installThe current CI suite runs the following tests:
-
PHPUnit
vendor/bin/phpunit
-
PHPSpec
vendor/bin/phpspec run
-
Behat (non-JS scenarios)
vendor/bin/behat --strict --tags="~@javascript" -
Behat (JS scenarios)
-
Start Headless Chrome:
google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
- Install SSL certificates (only once needed) and run test application's webserver on
127.0.0.1:8080:
symfony server:ca:install APP_ENV=test symfony server:start --port=8080 --dir=tests/TestApplication/public --daemon
- Run Behat:
vendor/bin/behat --strict --tags="@javascript" -
Static Analysis
-
Psalm
vendor/bin/psalm
-
PHPStan
vendor/bin/phpstan analyse -c phpstan.neon -l max src/
-
-
Coding Standard
vendor/bin/ecs check src
This library is under the MIT license. See the complete license in the LICENSE file.
Developed by Webgriffe®.
