gewebe / sylius-vat-plugin
带有验证功能的增值税号地址字段,Sylius的欧盟增值税率插件
v1.4.1
2024-05-07 23:05 UTC
Requires
- php: ^8.0
- ibericode/vat: ^2.0
- sylius/mailer-bundle: ^1.8 || ^2.0@beta
- sylius/sylius: ^1.12
- symfony/webpack-encore-bundle: ^1.15
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- phpspec/phpspec: ^7.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.1
- phpstan/phpstan-doctrine: 1.3.40
- phpstan/phpstan-strict-rules: ^1.3.0
- phpstan/phpstan-webmozart-assert: ^1.2.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sylius-labs/coding-standard: ^4.2
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/flex: ^2.2.2
- symfony/intl: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- vimeo/psalm: 5.12.0
Conflicts
- behat/mink-selenium2-driver: >=1.7.0
- symfony/framework-bundle: 6.2.8
README
功能
- 欧盟增值税率安装器,包含国家和区域
- 在
Address
和ShopBillingData
实体中添加新的增值税号字段 - 配置增值税号字段要求
- 可选/必填
- 如果客户填写了“公司”字段,则为必填
- 在选定的国家/地区为必填
- 验证增值税号
- 选定国家的格式
- 国家与选定国家相同
- 使用VIES API验证欧盟增值税号的有效性
- 在给定时间后重新验证客户的增值税号
- 如果
- 增值税号验证成功
- 客户的税务国家与商店账单国家不同
安装
通过composer下载插件
composer require gewebe/sylius-vat-plugin
在bundles.php中启用插件
# config/bundles.php return [ # ... Gewebe\SyliusVATPlugin\GewebeSyliusVATPlugin::class => ['all' => true], ];
导入插件配置
# config/packages/_sylius.yaml imports: # ... - { resource: '@GewebeSyliusVATPlugin/config/app/config.yml'}
配置税务地址
对于欧盟增值税,税务地址应设置为Sylius配置中的送货地址。
# config/packages/_sylius.yaml sylius_core: shipping_address_based_taxation: true
复制模板
将自定义模板复制到您的模板目录(例如 templates/bundles/
)
mkdir -p templates/bundles/SyliusAdminBundle/ cp -R vendor/gewebe/sylius-vat-plugin/templates/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/ mkdir -p templates/bundles/SyliusShopBundle/ cp -R vendor/gewebe/sylius-vat-plugin/templates/SyliusShopBundle/* templates/bundles/SyliusShopBundle/
扩展 Address
实体
# 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") */ #[ORM\Entity] #[ORM\Table(name: 'sylius_address')] class Address extends BaseAddress implements VatNumberAddressInterface { use VatNumberAwareTrait;
如果您使用yaml
映射,请也添加
# 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
添加或扩展 ShopBillingData
实体
# src/Entity/Channel/ShopBillingData.php namespace App\Entity\Channel; use Doctrine\ORM\Mapping as ORM; use Gewebe\SyliusVATPlugin\Entity\ShopBillingDataVatNumberAwareTrait; use Gewebe\SyliusVATPlugin\Entity\ShopBillingDataVatNumberInterface; use Sylius\Component\Core\Model\ShopBillingData as BaseShopBillingData; /** * @ORM\Entity * @ORM\Table(name="sylius_shop_billing_data") */ #[ORM\Entity] #[ORM\Table(name: 'sylius_shop_billing_data')] class ShopBillingData extends BaseShopBillingData implements ShopBillingDataVatNumberInterface { use ShopBillingDataVatNumberAwareTrait;
如果您使用yaml
映射,请也添加
# config/doctrine/ShopBillingData.orm.yaml App\Entity\Channel\ShopBillingData: type: entity table: sylius_shop_billing_data fields: vatNumber: type: string column: vat_number nullable: true
覆盖您的sylius配置中的shop_billing_data
资源
# config/packages/_sylius.yaml sylius_core: resources: shop_billing_data: classes: model: App\Entity\Channel\ShopBillingData
更新您的数据库模式
bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate
使用方法
安装欧盟国家和增值税率
# 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
验证客户增值税号
1. 创建新的订单,并在送货地址中填写增值税号
2. 在管理订单中显示增值税号和验证状态
测试
设置传统环境
$ composer install $ cd tests/Application $ yarn install $ yarn build $ bin/console assets:install public -e test $ bin/console doctrine:schema:create -e test $ export APP_ENV=test $ symfony server:start --port=8080 --dir=public
设置Docker
$ docker compose up -d
$ docker compose exec app make init
运行测试
$ vendor/bin/behat $ vendor/bin/phpspec run $ vendor/bin/phpstan analyse -c phpstan.neon -l max src/ $ vendor/bin/psalm
编码标准
$ vendor/bin/ecs check