asdoria / sylius-shipping-delivery-time-plugin
为产品添加配送时间。
0.1.0
2023-07-03 09:19 UTC
Requires
- php: ^8.0
- sylius/sylius: ^1.12
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
- phpspec/phpspec: ^7.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.1
- phpstan/phpstan-doctrine: 1.3.37
- phpstan/phpstan-strict-rules: ^1.3.0
- phpstan/phpstan-webmozart-assert: ^1.2.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sylius-labs/coding-standard: ^4.2
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/flex: ^2.2.2
- symfony/intl: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- vimeo/psalm: 5.9.0
README
安装
使用Composer安装插件
$ composer require asdoria/sylius-shipping-delivery-time-plugin
导入配置
# config/packages/asdoria_shipping_delivery_time.yaml imports: - { resource: "@AsdoriaSyliusShippingDeliveryTimePlugin/Resources/config/app/config.yaml" } # Uncomment next line if you're using Webpack Encore # - { resource: "@AsdoriaSyliusShippingDeliveryTimePlugin/Resources/config/app/config_webpack.yaml" }
导入路由
# config/routes/asdoria_shipping_delivery_time.yaml asdoria_sylius_shipping_delivery_time: resource: "@AsdoriaSyliusShippingDeliveryTimePlugin/Resources/config/routes.yaml"
或者如果您的应用不使用地区
# config/routes.yaml asdoria_sylius_shipping_delivery_time: resource: "@AsdoriaSyliusShippingDeliveryTimePlugin/Resources/config/routes_no_locale.yaml"
重写ShippingMethod实体
使App\Entity\Shipping\ShippingMethod
扩展ShippingMethodCountdownAwareInterface
use Asdoria\SyliusShippingDeliveryTimePlugin\Traits\Aware\ShippingMethodCountdownAwareTrait; use Asdoria\SyliusShippingDeliveryTimePlugin\Model\Aware\ShippingMethodCountdownAwareInterface; /** * Class ShippingMethod * * @author Philippe Vesin <pve.asdoria@gmail.com> */ class ShippingMethod extends BaseShippingMethod implements ShippingMethodCountdownAwareInterface { use ShippingMethodCountdownAwareTrait; /** * ShippingMethod constructor. */ public function __construct() { parent::__construct(); $this->initializeShippingSchedulesCollection(); } }
如果您不使用注解,则创建src/Resources/config/doctrine/Shipping/ShippingMethod.orm.xml
<mapped-superclass name="App\Entity\Shipping\ShippingMethod" table="sylius_shipping_method"> <field name="deliveryWeekdays" column="delivery_weekdays" nullable="true" type="array"/> <field name="deliveryMaxTime" column="delivery_max_time" nullable="true" type="integer"> <options> <option name="default">0</option> </options> </field> <field name="deliveryMinTime" column="delivery_min_time" nullable="true" type="integer"> <options> <option name="default">0</option> </options> </field> <one-to-many target-entity="Asdoria\SyliusShippingDeliveryTimePlugin\Model\ShippingScheduleInterface" mapped-by="shippingMethod" field="shippingSchedules" orphan-removal="true" > <cascade> <cascade-all/> </cascade> </one-to-many> <field name="additionalDeliveryTime" column="additional_delivery_time" nullable="true" type="json" /> </mapped-superclass>
重写Product实体
使App\Entity\Product\Product
扩展ProductCountdownAwareInterface
use Asdoria\SyliusShippingDeliveryTimePlugin\Model\Aware\ProductCountdownAwareInterface; use Asdoria\SyliusShippingDeliveryTimePlugin\Traits\Aware\ProductCountdownAwareTrait; /** * Class Product * @package App\Entity\Product * * @author Philippe Vesin <pve.asdoria@gmail.com> */ class Product extends BaseProduct implements ProductInterface, ProductCountdownAwareInterface { use ProductCountdownAwareTrait; }
如果您不使用注解,则创建src/Resources/config/doctrine/Product/Product.orm.xml
<mapped-superclass name="App\Entity\Product\Product" table="sylius_product"> <field name="additionalDeliveryTime" column="additional_delivery_time" nullable="true" type="integer"> <options> <option name="default">0</option> </options> </field> </mapped-superclass>
重写Channel实体
使App\Entity\Channel\Channel
扩展DefaultShippingZoneAwareInterface
use Asdoria\SyliusShippingDeliveryTimePlugin\Model\Aware\DefaultShippingZoneAwareInterface; use Asdoria\SyliusShippingDeliveryTimePlugin\Traits\Aware\DefaultShippingZoneAwareTrait; class Channel extends BaseChannel implements ChannelInterface, DefaultShippingZoneAwareInterface { use DefaultShippingZoneAwareTrait; }
如果您不使用注解,则创建src/Resources/config/doctrine/Channel/Channel.orm.xml
<mapped-superclass name="App\Entity\Channel\Channel" table="sylius_channel"> <many-to-one field="defaultShippingZone" target-entity="Sylius\Component\Addressing\Model\ZoneInterface"/> </mapped-superclass>
将插件类添加到您的bundles.php
<?php $bundles = [ // ... Asdoria\SyliusShippingDeliveryTimePlugin\AsdoriaSyliusShippingDeliveryTimePlugin::class => ['all' => true], // ... ];
- 从插件目录复制模板覆盖
From: [shop_dir] vendor/asdoria/sylius-shipping-delivery-time-plugin/Resources/views/bundles/SyliusAdminBundle/*
To: [shop_dir] templates/bundles/SyliusAdminBundle/*
更新您的数据库
bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate
安装资产
php bin/console assets:install
清除缓存
php bin/console cache:clear