setono/sylius-callout-plugin
最新稳定版本:v1.0.0-alpha.2
Composer 安装命令:
composer require setono/sylius-callout-plugin
包简介
Add callouts to your Sylius products
README 文档
README
The callout plugin for Sylius allows you to configure nice callouts/badges for sets of products based on specific rules. It provides a common set of rules by default and is very flexible when it comes to adding new ones.
Screenshots
Shop
Admin
Installation
Step 1: Download the plugin
$ composer require setono/sylius-callout-plugin
Step 2: Enable the plugin
Then, enable the plugin by adding it to the list of registered plugins/bundles
in config/bundles.php file of your project before (!) SyliusGridBundle:
<?php $bundles = [ Setono\SyliusCalloutPlugin\SetonoSyliusCalloutPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ];
Step 3: Configure plugin
# config/packages/setono_sylius_callout.yaml imports: - { resource: "@SetonoSyliusCalloutPlugin/Resources/config/app/config.yaml" }
Step 4: Import routing
# config/routes/setono_sylius_callout.yaml setono_sylius_callout: resource: "@SetonoSyliusCalloutPlugin/Resources/config/routes.yaml"
Step 5: Extend entities
Extend Product
Add the Setono\SyliusCalloutPlugin\Model\ProductTrait trait to your App\Entity\Product\Product class.
<?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; }
Step 6: Update your database schema
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
Step 7: Add callouts to your product templates
Add callouts to your product box template. By default, you should use templates/bundles/SyliusShopBundle/Product/_box.html.twig
path. Check out our _box.html.twig file for a reference.
Note the line: {% include "@SetonoSyliusCalloutPlugin/Shop/Product/Callout/_callouts.html.twig" with { 'callouts' : get_callouts(product, 'default') } %}.
Step 8: Using asynchronous transport (optional, but recommended)
All commands in this plugin will extend the CommandInterface. Therefore, you can route all commands easily by adding this to your Messenger config:
# 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
Step 9: Configure cron job
For the performance reasons, configure a cron job on your production server to execute $ bin/console setono:sylius-callout:assign command
once in a while in order to assign all callouts. In most cases it should be done by the resource event listener
triggered anytime you create/update a product or callout, but it is worth to have it covered if something goes wrong.
Step 10: Install assets
$ bin/console assets:install
Usage
From now on you should be able to add new callouts in the admin panel. Once you add one, you just need to configure.
Customization
Adding a new rule form
- Configure a new form under
App\Form\Type\Rulenamespace, - Add a rule checker under
App\Checker\Rulenamespace and make sure it implementsSetono\SyliusCalloutPlugin\Checker\Rule\ProductCalloutRuleCheckerInterfaceinterface and has apublic const TYPEset corresponding to the below service configuration - Register and tag new services:
<!-- 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>
统计信息
- 总下载量: 54.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-19


