gewebe/sylius-vat-plugin

带有验证功能的增值税号地址字段,Sylius的欧盟增值税率插件

安装数: 12,578

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 3

分支: 1

开放问题: 0

类型:sylius-plugin

This package is auto-updated.

Last update: 2024-09-08 00:44:53 UTC


README

Latest Version on Packagist Software License Build Quality Score

功能

  • 欧盟增值税率安装器,包含国家和区域
  • AddressShopBillingData 实体中添加新的增值税号字段
  • 配置增值税号字段要求
    • 可选/必填
    • 如果客户填写了“公司”字段,则为必填
    • 在选定的国家/地区为必填
  • 验证增值税号
    • 选定国家的格式
    • 国家与选定国家相同
    • 使用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. 创建新的订单,并在送货地址中填写增值税号

Screenshot checkout address with vat number

2. 在管理订单中显示增值税号和验证状态

Screenshot order shipping address with vat number

测试

设置传统环境

$ 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