setono / sylius-callout-plugin
为您的Sylius产品添加呼出功能
v0.5.0-alpha.3
2024-02-05 12:15 UTC
Requires
- php: >=8.1
- doctrine/collections: ^1.8
- doctrine/event-manager: ^1.2
- doctrine/orm: ^2.15
- doctrine/persistence: ^2.5 || ^3.2
- ocramius/doctrine-batch-utils: ^2.4
- psr/event-dispatcher: ^1.0
- setono/composite-compiler-pass: ^1.1
- setono/doctrine-object-manager-trait: ^1.2
- sylius/channel: ^1.0
- sylius/channel-bundle: ^1.0
- sylius/core: ^1.0
- sylius/core-bundle: ^1.0
- sylius/locale: ^1.0
- sylius/product: ^1.0
- sylius/product-bundle: ^1.0
- sylius/promotion: ^1.0
- sylius/registry: ^1.0
- sylius/resource-bundle: ^1.6
- sylius/taxonomy: ^1.0
- sylius/taxonomy-bundle: ^1.0
- sylius/ui-bundle: ^1.0
- symfony/config: ^5.4 || ^6.4
- symfony/console: ^5.4 || ^6.4
- symfony/dependency-injection: ^5.4 || ^6.4
- symfony/deprecation-contracts: ^2.5
- symfony/event-dispatcher: ^5.4 || ^6.4
- symfony/form: ^5.4 || ^6.4
- symfony/http-foundation: ^5.4 || ^6.4
- symfony/messenger: ^5.4 || ^6.4
- symfony/options-resolver: ^5.4 || ^6.4
- symfony/routing: ^5.4 || ^6.4
- symfony/translation-contracts: ^2.5 || ^3.1
- symfony/twig-bundle: ^5.4 || ^6.4
- symfony/validator: ^5.4 || ^6.4
- twig/twig: ^2.15 || ^3.8
- webmozart/assert: ^1.11
Requires (Dev)
- api-platform/core: ^2.7.16
- babdev/pagerfanta-bundle: ^3.8
- behat/behat: ^3.14
- doctrine/doctrine-bundle: ^2.11
- fakerphp/faker: ^1.23
- jms/serializer-bundle: ^4.2
- lexik/jwt-authentication-bundle: ^2.17
- matthiasnoback/symfony-config-test: ^4.3
- matthiasnoback/symfony-dependency-injection-test: ^4.3 || ^5.0
- phpspec/prophecy-phpunit: ^2.1
- phpunit/phpunit: ^9.6
- polishsymfonycommunity/symfony-mocker-container: ^1.0.7
- psalm/plugin-phpunit: ^0.18
- psalm/plugin-symfony: ^5.1
- setono/code-quality-pack: ^2.6
- sylius/sylius: ~1.12.13
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/intl: ^5.4 || ^6.0
- symfony/property-info: ^5.4 || ^6.0
- symfony/serializer: ^5.4 || ^6.0.1
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- symfony/webpack-encore-bundle: ^1.17
- willdurand/negotiation: ^3.1
README
Sylius的呼出插件允许您根据特定规则为产品集合配置漂亮的呼出/徽章。它默认提供一组规则,并在添加新规则时非常灵活。
截图
商店
管理员
安装
步骤 1: 下载插件
$ composer require setono/sylius-callout-plugin
步骤 2: 启用插件
然后,通过将其添加到项目中config/bundles.php
文件中已注册插件/包列表来启用插件(在SyliusGridBundle
之前)
<?php $bundles = [ Setono\SyliusCalloutPlugin\SetonoSyliusCalloutPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ];
步骤 3: 配置插件
# config/packages/setono_sylius_callout.yaml imports: - { resource: "@SetonoSyliusCalloutPlugin/Resources/config/app/config.yaml" }
步骤 4: 导入路由
# config/routes/setono_sylius_callout.yaml setono_sylius_callout: resource: "@SetonoSyliusCalloutPlugin/Resources/config/routes.yaml"
步骤 5: 扩展实体
扩展Product
将Setono\SyliusCalloutPlugin\Model\ProductTrait
特性添加到您的App\Entity\Product\Product
类中。
<?php // src/Entity/Product/Product.php namespace App\Entity; use Setono\SyliusCalloutPlugin\Model\ProductTrait as CalloutProductTrait; use Setono\SyliusCalloutPlugin\Model\ProductInterface as CalloutProductInterface; use Sylius\Component\Core\Model\Product as BaseProduct; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements CalloutProductInterface { use CalloutProductTrait; }
步骤 6: 更新您的数据库模式
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
步骤 7: 将呼出功能添加到您的产品模板
将呼出功能添加到您的产品盒模板。默认情况下,您应该使用templates/bundles/SyliusShopBundle/Product/_box.html.twig
路径。查看我们的_box.html.twig文件作为参考。
注意以下行:{% include "@SetonoSyliusCalloutPlugin/Shop/Product/Callout/_callouts.html.twig" with { 'callouts' : get_callouts(product, 'default') } %}
。
步骤 8: 使用异步传输(可选,但推荐)
此插件中的所有命令都将扩展CommandInterface。因此,您可以通过添加到您的消息传递器配置来轻松地将所有命令路由。
# config/packages/messenger.yaml framework: messenger: routing: # Route all command messages to the async transport # This presumes that you have already set up an 'async' transport 'Setono\SyliusCalloutPlugin\Message\Command\CommandInterface': async
步骤 9: 配置cron作业
出于性能原因,在您的生产服务器上配置cron作业以定期执行$ bin/console setono:sylius-callout:assign
命令,以分配所有呼出功能。在大多数情况下,它应该通过资源事件监听器在创建/更新产品或呼出时触发,但如果出现问题,值得覆盖这一点。
步骤 10: 安装资源
$ bin/console assets:install
使用方法
从现在开始,您应该能够在管理员面板中添加新的呼出功能。一旦添加,只需进行配置即可。
自定义
添加新的规则表单
- 在
App\Form\Type\Rule
命名空间下配置新的表单, - 在
App\Checker\Rule
命名空间下添加规则检查器,并确保它实现了Setono\SyliusCalloutPlugin\Checker\Rule\ProductCalloutRuleCheckerInterface
接口,并设置了一个public const TYPE
与以下服务配置相对应 - 注册和标记新的服务
<!-- services.xml --> <services> ... <service id="app.callout_rule_checker.is_on_sale" class="Setono\SyliusCalloutPlugin\Callout\Checker\Rule\IsOnSaleRuleChecker"> <argument type="service" id="setono_sylius_callout.checker.product_promotion" /> <tag name="setono_sylius_callout.callout_rule_checker" type="is_on_sale" label="setono_sylius_callout.ui.is_on_sale" form-type="Setono\SyliusCalloutPlugin\Form\Type\Rule\IsOnSaleConfigurationType" /> </service> <service id="app.form.type.rule.is_on_sale" class="Setono\SyliusCalloutPlugin\Form\Type\Rule\IsOnSaleConfigurationType"> <tag name="form.type" /> </service> </services>