flux-se/sylius-eu-vat-plugin
Composer 安装命令:
composer require flux-se/sylius-eu-vat-plugin
包简介
Add EU VAT field and validation for Sylius using VIES API Webservice.
README 文档
README
EU VAT field and validation for Sylius using VIES API Webservice
This plugin is adding :
- two new attributes to the
Channelentity allowing to know from which country your shop is from and what's the European zone to target - VAT Number field to the
Addressentity - validation over VIES API on this field
- validation of the address country (vat number country should equal to the address country)
- the basic European rule allowing the seller not to charge
VAT to foreign European customers who have provided a valid VAT number :
- (Shop country === customer country vat number) then do nothing
- (Shop country !== customer country vat number) then remove taxes
Screenshots
Shop checkout
Shop account
Installation
composer require flux-se/sylius-eu-vat-plugin
Configuration
Enable this plugin :
<?php # config/bundles.php return [ // ... FluxSE\SyliusEUVatPlugin\FluxSESyliusEUVatPlugin::class => ['all' => true], // ... ];
Add default config if you want to get access to the default fixtures this plugin need.
# config/packages/flux_se_sylius_eu_vat.yaml imports: - { resource: "@FluxSESyliusEUVatPlugin/config/config.yaml" } # If you are using SyliusAdminBundle - { resource: "@FluxSESyliusEUVatPlugin/config/admin.yaml" } # If you are using SyliusShopBundle - { resource: "@FluxSESyliusEUVatPlugin/config/shop.yaml" }
Update Channel entity : src/Entity/Channel/Channel.php
<?php declare(strict_types=1); namespace App\Entity\Channel; use Doctrine\ORM\Mapping as ORM; use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareTrait; use Sylius\Component\Core\Model\Channel as BaseChannel; #[ORM\Entity] #[ORM\Table(name: 'sylius_channel')] class Channel extends BaseChannel implements ChannelInterface { use EuropeanChannelAwareTrait; }
And the corresponding interface : src/Entity/Channel/ChannelInterface.php
<?php declare(strict_types=1); namespace App\Entity\Channel; use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareInterface; use Sylius\Component\Core\Model\ChannelInterface as BaseChannelInterface; interface ChannelInterface extends BaseChannelInterface, EuropeanChannelAwareInterface { }
Click me : if you are using YAML ORM definitions
# config/doctrine/Address.orm.yml App\Entity\Adressing\Address : type: entity table: sylius_address fields: vatNumber: name: vat_number type: string nullable: true
Then change the default Sylius model class :
# config/packages/sylius_channel.yaml sylius_channel: resources: channel: classes: model: App\Entity\Channel\Channel
Update Address entity : src/Entity/Addressing/Address.php
<?php declare(strict_types=1); namespace App\Entity\Addressing; use Doctrine\ORM\Mapping as ORM; use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareTrait; use Sylius\Component\Core\Model\Address as BaseAddress; #[ORM\Entity] #[ORM\Table(name: 'sylius_address')] class Address extends BaseAddress implements AddressInterface { use VATNumberAwareTrait; }
And the corresponding interface : src/Entity/Addressing/AddressInterface.php
<?php declare(strict_types=1); namespace App\Entity\Addressing; use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface; use Sylius\Component\Core\Model\AddressInterface as BaseAddressInterface; interface AddressInterface extends BaseAddressInterface, VATNumberAwareInterface { }
Click me : if you are using YAML ORM definitions
# config/doctrine/Channel.orm.yml App\Entity\Channel\Channel: type: entity table: sylius_channel manyToOne: baseCountry: targetEntity: Sylius\Component\Addressing\Model\CountryInterface fetch: EAGER joinColumn: name: base_country_id onDelete: "SET NULL" europeanZone: targetEntity: Sylius\Component\Addressing\Model\ZoneInterface fetch: EAGER joinColumn: name: european_zone_id onDelete: "SET NULL"
Then change the default Sylius model class :
# config/packages/sylius_addressing.yaml sylius_addressing: resources: address: classes: model: App\Entity\Addressing\Address
Update your database :
# This bundle use doctrine migrations ^3 (see `src/Migrations` folder for more details)
php ./bin/console doctrine:migrations:migrate
Load some required fixtures :
./bin/console sylius:fixture:load european_vat_zones
Go to your admin panel and edit your Channel to set the two fields to indicate to this plugin :
- What is your base country to compare to your customer country.
- What is the European zone to know if the customer is part of the Europe or not.
Fixtures
You can add some fixtures to auto-configure your channel, for example add this into a yaml file :
# config/packages/my_fixtures.yaml sylius_fixtures: suites: french_european_channel: listeners: logger: ~ fixtures: address_with_vat_number: options: custom: my_customer: first_name: "John" last_name: "Doe" phone_number: "+33912345678" company: "My Company Inc." street: "1234 Street Avenue" city: "London" postcode: "1234" country_code: "GB" customer: "john.doe@mycompany.com" vat_number: ~ # could also be "GB123456789" eu_vat_plugin_european_channel: options: custom: default: channel: "default_channel_code" # Put an existing Channel code base_country: "FR" # Existing Country code european_zone: "EU" # Existing Zone code
API
flux-se/sylius-eu-vat-plugin 适用场景与选型建议
flux-se/sylius-eu-vat-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.17k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2021 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 flux-se/sylius-eu-vat-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flux-se/sylius-eu-vat-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 26.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-05



