setono / sylius-callout-plugin
Add callouts to your Sylius products
Installs: 48 433
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 13
Open Issues: 4
Type:sylius-plugin
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
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\Rule
namespace, - Add a rule checker under
App\Checker\Rule
namespace and make sure it implementsSetono\SyliusCalloutPlugin\Checker\Rule\ProductCalloutRuleCheckerInterface
interface and has apublic const TYPE
set 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>