flux-se/sylius-eu-vat-plugin

使用 VIES API Web 服务为 Sylius 添加欧盟增值税字段和验证。

安装次数: 13,038

依赖项: 0

建议者: 0

安全: 0

星标: 16

关注者: 4

分支: 8

公开问题: 1

类型:sylius-plugin


README

Latest Version on Packagist Software License Build Status Quality Score

使用 VIES API Web 服务为 Sylius 添加欧盟增值税字段和验证

此插件添加了

  • 两个新属性到 Channel 实体,允许知道您的商店来自哪个国家以及要针对哪个欧洲区域
  • Address 实体的增值税号字段
  • 对此字段进行 VIES API 验证
  • 验证地址国家(增值税号国家应等于地址国家)
  • 基本欧洲规则,允许卖家不对提供有效增值税号的国外欧洲客户征收增值税
    • (商店国家 === 客户国家增值税号)则不做任何操作
    • (商店国家 !== 客户国家增值税号)则移除税费

屏幕截图

商店结账

Shop checkout address step form

Shop checkout summary page

商店账户

Shop account address book

Shop account order details

安装

composer require flux-se/sylius-eu-vat-plugin

配置

启用此插件

<?php

# config/bundles.php

return [
    // ...
    FluxSE\SyliusEUVatPlugin\FluxSESyliusEUVatPlugin::class => ['all' => true],
    // ...
];

如果您想访问此插件所需的默认固定值,请添加默认配置。

# config/packages/flux_se_sylius_eu_vat.yaml

imports:
    - { resource: "@FluxSESyliusEUVatPlugin/config/config.yaml" }
    # If you are using SyliusAdminBundle
    - { resource: "@FluxSESyliusEUVatPlugin/config/admin.yaml" }

将 Sylius 覆盖的模板复制到您的模板目录中(例如 templates/bundles/

# If you are using SyliusAdminBundle
mkdir -p templates/bundles/SyliusAdminBundle/
cp -R vendor/flux-se/sylius-eu-vat-plugin/templates/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/

# If you are using SyliusShopBundle
mkdir -p templates/bundles/SyliusShopBundle/
cp -R vendor/flux-se/sylius-eu-vat-plugin/templates/SyliusShopBundle/* templates/bundles/SyliusShopBundle/

更新 Channel 实体: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")
 */
#[ORM\Entity]
#[ORM\Table(name: 'sylius_channel')]
class Channel extends BaseChannel implements ChannelInterface
{
    use EuropeanChannelAwareTrait;
}

以及相应的接口: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
{
}
点击我:如果您使用 YAML ORM 定义
# config/doctrine/Address.orm.yml

App\Entity\Adressing\Address :
    type: entity
    table: sylius_address

    fields:
        vatNumber:
            name: vat_number
            type: string
            nullable: true

然后更改默认的 Sylius 模型类

# config/packages/sylius_channel.yaml

sylius_channel:
    resources:
        channel:
            classes:
                model: App\Entity\Channel\Channel

更新 Address 实体: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")
 */
#[ORM\Entity]
#[ORM\Table(name: 'sylius_address')]
class Address extends BaseAddress implements AddressInterface
{
    use VATNumberAwareTrait;
}

以及相应的接口: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
{
}
点击我:如果您使用 YAML ORM 定义
# 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"

然后更改默认的 Sylius 模型类

# config/packages/sylius_addressing.yaml

sylius_addressing:
    resources:
        address:
            classes:
                model: App\Entity\Addressing\Address

更新您的数据库

# This bundle use doctrine migrations ^3 (see `src/Migrations` folder for more details)
php ./bin/console doctrine:migrations:migrate

加载一些必需的固定值

./bin/console sylius:fixture:load european_vat_zones

转到您的管理面板并编辑您的 Channel 以设置两个字段,以指示此插件

  1. 您的基准国家与您的客户国家进行比较。
  2. 确定客户是否属于欧洲。

固定值

您可以为您的渠道添加一些固定值以自动配置,例如,将以下内容添加到 yaml 文件中

# 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