The product callouts plugin for Sylius allows you to configure nice badges for different set of products based on specific rules. It provides a common set of configuration by default and is very flexible when it comes to adding new ones.
$ composer require setono/callouts-plugin
- Add plugin dependencies to your bundles.php file:
$bundles = [
...
OldSound\RabbitMqBundle\OldSoundRabbitMqBundle::class => ['all' => true],
Setono\SyliusCalloutsPlugin\SetonoSyliusCalloutsPlugin:class => ['all' => true],
]);
- Import required config in your
app/config/config.yml
file:
# config/packages/_sylius.yaml
imports:
...
- { resource: "@SetonoSyliusCalloutsPlugin/Resources/config/config.yml" }
- Import routing on top of your
app/config/routing.yml
file:
# config/routes/routes.yaml
setono_product_callouts_plugin:
resource: "@SetonoSyliusCalloutsPlugin/Resources/config/routing.yml"
- Install assets
$ bin/console assets:install --symlink
- Customize your product model. Read more about Sylius models customization here.
- add a
Setono\SyliusCalloutsPlugin\Model\CalloutsAwareTrait
trait to yourApp\Entity\Product
class (check our this path for a reference), - add callouts relation to your
Product.orm.xml
like here, - if you haven't done so already, configure the
sylius_product
resource to point to yourApp\Entity\Product
like we did in an example here.
Note: We are using .orm.xml
file format for entities configuration. You can use whatever format you wish. For more details
read the official Symfony Doctrine configuration reference or
check out our configuration here.
- 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 thesetono_render_callouts
Twig function that usesSetono\SyliusCalloutsPlugin\Model\CalloutsAwareInterface
as a first parameter andposition
as a second one. Currently available positions are:
top_left_corner
top_right_corner
bottom_right_corner
bottom_left_corner
-
Configure Async assigns product callouts
This plugin assigns product callouts when the administrator create/update the product or callout. With a large number of products this can result in slower page performance. To circumvent this problem you can use an async transport with Symfony Messenger to assigns product callouts.
Follow the installation instructions here: How to Use the Messenger and then configure a transport.
Basically you should do:
$ composer req symfony/messenger symfony/serializer-pack
Then configure the Messenger component:
# config/packages/messenger.yaml framework: messenger: transports: amqp: "%env(MESSENGER_TRANSPORT_DSN)%"
# .env ###> symfony/messenger ### MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages ###< symfony/messenger ###
And finally configure the plugin to use your transport:
setono_sylius_callouts: messenger: transport: amqp
After this, the Messenger will be automatically enabled in this plugin and subsequently, it will assign product callouts asynchronously.
-
For the performance reasons, configure a cron job on your production server to execute
$ bin/console setono:callouts:assign
command once in a while in order to rebuild the index for 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.
From now on you should be able to add new callouts in the admin panel. Once you add one, you just need to configure.
- Configure a new form under
App\Form\Type\Rule
namespace like this IsOnSaleConfigurationType, - Add a rule checker under
App\Checker\Rule
namespace like this IsOnSaleRuleChecker and make sure it implementsSetono\SyliusCalloutsPlugin\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="setono_sylius_callouts_plugin.callout_rule_checker.is_on_sale" class="Setono\SyliusCalloutsPlugin\Checker\Rule\IsOnSaleRuleChecker">
<argument type="service" id="setono_sylius_callouts_plugin.checker.product_promotion" />
<tag name="setono_sylius_callouts_plugin.callout_rule_checker" type="is_on_sale" label="setono_sylius_callouts_plugin.ui.is_on_sale" form-type="Setono\SyliusCalloutsPlugin\Form\Type\Rule\IsOnSaleConfigurationType" />
</service>
<service id="setono.form.type.rule.is_on_sale" class="Setono\SyliusCalloutsPlugin\Form\Type\Rule\IsOnSaleConfigurationType">
<tag name="form.type" />
</service>
</services>
$ bin/console debug:container | grep setono_sylius_callouts_plugin
- PHPSpec
$ vendor/bin/phpspec run
- Behat (non-JS scenarios)
$ vendor/bin/behat --tags="~@javascript"
- Behat (JS scenarios)
- Download Chromedriver
- Download Selenium Standalone Server.
- Run Selenium server with previously downloaded Chromedriver:
$ java -Dwebdriver.chrome.driver=chromedriver -jar selenium-server-standalone.jar
- Run test application's webserver on
localhost:8080
:
$ (cd tests/Application && bin/console server:run localhost:8080 -d public -e test)
- Run Behat:
$ vendor/bin/behat
- Using
test
environment:
$ (cd tests/Application && bin/console sylius:fixtures:load -e test)
$ (cd tests/Application && bin/console server:run -d public -e test)
- Using
dev
environment:
$ (cd tests/Application && bin/console sylius:fixtures:load -e dev)
$ (cd tests/Application && bin/console server:run -d public -e dev)
Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.