arobases / sylius-transporter-label-generation-plugin
为 sylius 开发的 Arobases 运输标签生成插件
0.0.19
2024-03-18 11:07 UTC
Requires
- php: ^7.4 || ^8.0
- ext-simplexml: *
- ext-soap: *
- sylius/sylius: 1.10.14
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
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- phpspec/phpspec: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: 0.12.99
- phpstan/phpstan-doctrine: 0.12.33
- phpstan/phpstan-strict-rules: ^0.12.0
- phpstan/phpstan-webmozart-assert: 0.12.12
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^4.4 || ^5.2
- symfony/debug-bundle: ^4.4 || ^5.2
- symfony/dotenv: ^4.4 || ^5.2
- symfony/intl: ^4.4 || ^5.2
- symfony/web-profiler-bundle: ^4.4 || ^5.2
- vimeo/psalm: 4.7.1
- dev-main
- 0.0.19
- 0.0.18
- 0.0.17
- 0.0.16
- 0.0.15
- 0.0.14
- 0.0.13
- 0.0.12
- 0.0.11
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- dev-dependabot/composer/vimeo/psalm-5.9.0
- dev-dependabot/composer/phpstan/phpstan-doctrine-0.12.44
- dev-dependabot/composer/phpstan/phpstan-0.12.100
- dev-dependabot/composer/phpstan/phpstan-webmozart-assert-0.12.16
This package is auto-updated.
Last update: 2024-09-18 12:13:45 UTC
README
安装
步骤 1: 下载插件
composer require arobases/sylius-transporter-label-generation-plugin
步骤 2: 启用插件
<?php # config/bundles.php return [ Arobases\SyliusTransporterLabelGenerationPlugin\ArobasesSyliusTransporterLabelGenerationPlugin::class => ['all' => true], ];
步骤 3: 导入路由
# config/routes.yaml arobases_sylius_transporter_label_generation_admin: resource: "@ArobasesSyliusTransporterLabelGenerationPlugin/Resources/config/admin_routing.yml" prefix: /admin
步骤 4: 导入配置
# config/packages/arobases_sylius_transporter_label_generation.yaml imports: - { resource: "@ArobasesSyliusTransporterLabelGenerationPlugin/Resources/config/resources.yaml" }
步骤 5: 包含特质
重写 Shipment 实体以包含 TransporterTrait
# Entity/Shipping/Shipment.php /** * @ORM\Entity * @ORM\Table(name="sylius_shipment") */ class Shipment extends BaseShipment { use TransporterTrait; }
重写 Address 实体以包含 PickupPointTrait
# Entity/Addressing/Address.php /** * @ORM\Entity * @ORM\Table(name="sylius_address") */ class Address extends BaseAddress { use PickupPointTrait; }
重写 Product 实体以包含 HsCodeTrait 并添加字段到你的表单
# Entity/Product/Product.php /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct { use HsCodeTrait; }
# Form/Extension/Product/ProductTypeExtension.php ->add('hsCode', TextType::class,[ 'label' => "arobases_sylius_transporter_label_generation_plugin.form.product.hs_code", 'required' => false ])
# Product/Tab/_details.html.twig
{{ form_row(form.hsCode) }}
重写 OrderRepository 或添加 'findByShipment'
# OrderRepository.php public function findByShipment($transporterId): QueryBuilder { $qb = $this->createQueryBuilder('o') ->leftJoin('o.shipments', 'shipment') ->leftJoin('shipment.transporter', 'transporter') ->andWhere('transporter.id = :transporterId') ->andWhere('o.shippingState IN (:shippingState)') ->andWhere('o.paymentState IN (:paymentState)') ->setParameter('transporterId', $transporterId) ->setParameter('shippingState', ["ready", "shipped", "in_preparation"]) ->setParameter('paymentState', ["paid"]) ; return $qb; }
步骤 6: 更新数据库
bin/console doctrine:migration:migrate
不要忘记运行以下命令来生成你的文件
bin/console asset:install bin/console sylius:theme:asset:install
工作原理
!!! 考虑为标签生成允许文件写入(public/upload/label/colissimo) !!!
添加运输商
目前,你只能添加 Colissimo 运输商。要添加另一个,重写 TransporterType 并添加更多选项
# TransporterType.php ->add('name', ChoiceType::class, [ 'label' => 'sylius.ui.name', 'choices' => [ 'Colissimo' => 'colissimo', 'another transporter' => 'another_transporter' ], ])
创建另一个类似于 ColissimoRequest 服务的连接器服务,并完成 OrderLabelController.php 以处理其他运输商。