Josselin Dionisi - Freelance developer

Automate promo notifications on Sylius

ionicons-v5-k Josselin Dionisi Mar 16, 2025
80 reads Level: intermediate

Hello and thank you for clicking on this article! 🙂

Today we're going to talk about ... Sylius, and yes again. Version 2.0 having recently been released it's an opportunity to test some interesting things.

This article follows on from the previous one

This time we're going to take a look at another widely-used method for converting leads.

Imagine you're on an e-commerce site and you're interested in a product. You put it in the shopping cart to keep it aside, and you'll buy it later.

Okay, but now imagine that following this action you're notified a few days later that this product has just been put on special offer.

How about that? You've just automatically saved money. 😛

That's exactly what your customers will be thinking, and we're going to implement this process.

Sylius native events

In the previous article, I talked about Symfony's EventListener/EventSubscriber. We saw how practical it was to use these events to create very specific actions.

Sylius has its own internal events that allow us to "catcall" key moments such as adding to the shopping cart, placing an order, and so on.

Here, we're going to take a closer look at an administrator-side event, namely the creation/update of a promotion.

Here's a diagram summarizing what we want to set up:

  1. A prospect adds an item to his shopping cart
  2. An administrator creates or updates a promotion including this product
  3. We catch the Sylius event sylius . catalog_promotion . post_create or sylius . catalog_promotion . post_update and retrieve all customers who have this product in their shopping cart.
  4. For each one, you can send an email to notify them of the promotion.

Create a customized event based on Sylius events

Here's an example of what our event listener might look like

Now it's up to you to perform the actions you wish in a method of this custom event.

Once written, as usual, we need to declare it as a service and pass it the Sylius root event.

Testing our solution

So we've got our event listened to, a custom method for processing the information and notifying users. Now all we have to do is test it! 😛

Let's create a little promotion in the Sylius back-office

Here you can configure the promotion you want, as long as your method code matches it. For my part, I want to warn users interested in the Ethereal Drift T shirt that a 10% promotion is running.

I then click on Create or Update as the case may be, and immediately an email is sent to the targeted customers. That's it, our solution is up and running! 🙂

Every time a product promotion is created or updated, customers with one of the products in their basket will be notified.

Practical, isn't it? 😀

Thanks for reading this article to the end, I'm going back to experimenting on my own and I'll tell you more soon 😛