gewebe/sylius-vat-plugin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gewebe/sylius-vat-plugin

Composer 安装命令:

composer require gewebe/sylius-vat-plugin

包简介

VAT number address field with validation, EU VAT rates plugin for Sylius

README 文档

README

Latest Version on Packagist Software License Build Quality Score

Features

  • Installer for EU VAT rates with countries and zones
  • New fields for VAT number at Address and ShopBillingData entity
  • Configure VAT number field requirement:
    • Optional / Required
    • Required if customer filled “Company” field
    • Required in selected countries
  • Validate VAT number:
    • Format for selected country
    • Country is same as selected country
    • Validity using VIES API for EU VAT number
  • Revalidate customers VAT numbers after a given time
  • Placing an order without VAT in the EU, if
    • VAT number validation was successful
    • Customers taxation country is different from shop billing country

Installation

Download the plugin via composer

composer require gewebe/sylius-vat-plugin

Enable the plugin in bundles.php

# config/bundles.php

return [
    # ...
    
    Gewebe\SyliusVATPlugin\GewebeSyliusVATPlugin::class => ['all' => true],
];

Import the plugin configurations

# config/packages/_sylius.yaml

imports:
    # ...
       
    - { resource: '@GewebeSyliusVATPlugin/config/config.yaml'}

Configure taxation address

For EU VAT, the address for taxation should be set to the shipping address in the Sylius configuration.

# config/packages/_sylius.yaml

sylius_core:
    shipping_address_based_taxation: true

Copy templates

Copy customized templates to your templates directory (e.g 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/

Extend Address entity

# 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;

If you use yaml mapping add also:

# 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

Add or Extend ShopBillingData entity

# 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;

If you use yaml mapping add also:

# 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

Override the resource for shop_billing_data in your sylius config:

# config/packages/_sylius.yaml

sylius_core:
    resources:
        shop_billing_data:
            classes:
                model: App\Entity\Channel\ShopBillingData

Update your database schema

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

Usage

Install EU countries and VAT rates

# 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

Validate customers VAT number

1. Create new order with VAT number at shipping address

Screenshot checkout address with vat number

2. Show VAT number and validation status at admin orders

Screenshot order shipping address with vat number

Testing

Traditional

  1. From the plugin skeleton root directory, run the following commands:

    (cd vendor/sylius/test-application && yarn install)
    (cd vendor/sylius/test-application && yarn build)
    vendor/bin/console assets:install
    
    vendor/bin/console doctrine:database:create
    vendor/bin/console doctrine:migrations:migrate -n
    # Optionally load data fixtures
    vendor/bin/console sylius:fixtures:load -n

To be able to set up a plugin's database, remember to configure your database credentials in tests/TestApplication/.env and tests/TestApplication/.env.test.

  1. Run your local server:

    symfony server:ca:install
    symfony server:start -d
  2. Open your browser and navigate to https://localhost:8000.

Docker

  1. Execute make init to initialize the container and install the dependencies.

  2. Execute make database-init to create the database and run migrations.

  3. (Optional) Execute make load-fixtures to load the fixtures.

  4. Your app is available at http://localhost.

Usage

Running plugin tests

  • PHPUnit

    vendor/bin/phpunit
  • Behat (non-JS scenarios)

    vendor/bin/behat --strict --tags="~@javascript&&~@mink:chromedriver"
  • PHPStan - Static Analysis

    vendor/bin/phpstan analyse -c phpstan.neon -l max src/  
    • Coding Standard

      vendor/bin/ecs check

gewebe/sylius-vat-plugin 适用场景与选型建议

gewebe/sylius-vat-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.36k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2021 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「vat」 「e-commerce」 「sylius」 「sylius-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gewebe/sylius-vat-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gewebe/sylius-vat-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 gewebe/sylius-vat-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-07