3brs/sylius-payment-restrictions-plugin

Sylius 支付限制插件

v2.1.0 2024-01-04 08:33 UTC

This package is auto-updated.

Last update: 2024-08-30 01:29:00 UTC


README

支付限制插件

功能

  • 通过区域限制支付方式。这允许将选定的支付方式限制为特定区域或配送地址。
  • 通过配送方式限制支付方式 - 这意味着它可以禁用特定的配送-支付组合。

安装

  1. 运行 $ composer require 3brs/sylius-payment-restrictions-plugin

  2. 将插件类添加到您的 config/bundles.php

    return [
       ...
       ThreeBRS\SyliusPaymentRestrictionPlugin\ThreeBRSSyliusPaymentRestrictionPlugin::class => ['all' => true],
    ];
  3. 您的实体 PaymentMethod 必须实现 \ThreeBRS\SyliusPaymentRestrictionPlugin\Model\PaymentMethodRestrictionInterface。您可以使用特性 ThreeBRS\SyliusPaymentRestrictionPlugin\Model\PaymentMethodRestrictionTrait

    <?php 
    
    declare(strict_types=1);
    
    namespace App\Entity\Payment;
    
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\ORM\Mapping as ORM;
    use Sylius\Component\Core\Model\Payment as BasePayment;
    use ThreeBRS\SyliusPaymentRestrictionPlugin\Model\PaymentMethodRestrictionInterface;
    use ThreeBRS\SyliusPaymentRestrictionPlugin\Model\PaymentMethodRestrictionTrait;
    
    /**
     * @ORM\Entity
     * @ORM\Table(name="sylius_payment_method")
     */
    class PaymentMethod extends BasePayment implements PaymentMethodRestrictionInterface
    {
        use PaymentMethodRestrictionTrait;
    
        public function __construct()
        {
            parent::__construct();
        
            $this->shippingMethods = new ArrayCollection();
        }
    }
  4. 添加到 @SyliusAdmin/PaymentMethod/_form.html.twig(您可能需要复制粘贴原始内容,因为没有方法可以扩展该部分)

    {# ... #}
    
    <div class="ui segment">
    
        {# ... #}
        
        <div class="two fields">
            {{ form_row(form.zone) }}
            {{ form_row(form.shippingMethods) }}
        </div>
    </div>
    
    {# ... #}
  5. 创建并运行 doctrine 数据库迁移

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

开发

使用

  • /src 中修改插件
  • 查看 bin/ 目录以获取有用的命令

测试

在您的更改之后,您必须确保测试仍然通过。

composer install
bin/console doctrine:database:create --if-not-exists --env=test
bin/console doctrine:schema:update --complete --force --env=test
yarn --cwd tests/Application install
yarn --cwd tests/Application build

bin/behat
bin/phpstan.sh
bin/ecs.sh
vendor/bin/phpspec run

使用您的插件打开 Sylius

  1. 安装 symfony CLI 命令: https://symfony.com.cn/download
    • 提示:对于 Docker(使用 Ubuntu),使用 Debian/Ubuntu — 基于 APT 的 Linux 安装步骤作为 root 用户,且不需要 sudo 命令
      • 您可能需要先安装 curl apt-get update && apt-get install curl --yes
  2. 运行应用程序
(cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load)
(cd tests/Application && APP_ENV=test symfony server:start --dir=public --port=8080)
  • 如果需要,将 APP_ENV 修改为 dev

许可证

此库受 MIT 许可证的保护。

鸣谢

3BRS 开发。
manGoweb 分支而来。