Subscribers | Medusa Development Course
By Viktor Holik
By Viktor Holik
Welcome to our Medusa Development Course! In this series, you'll learn how to get your development environment ready and take your first steps in building a Medusa-powered e-commerce application. We'll walk you through everything step by step, helping you master Medusa’s modular architecture and build the key features you need.
This course was made by Viktor Holik, our Software Engineer and Medusa Expert.
In this guide, we’ll create and customize subscribers in Medusa to respond to key events, like sending an email when an order is placed. By setting up these event listeners, you can automate important follow-up actions and improve the user experience.
You can find the transcription of the guide below.
In Medusa, Subscribers are even listeners that run specific action when something happens, like an order being placed. For example, you can use a subscriber to send an email when a customer makes an order.
Here's an example from the README.md file in the Subscribers folder that shows how to listen to the order placed event. I will copy an example and create new file in the Subscribers folder, order-created-handler and just paste the code. Instead of providing order service as a value, I will provide order service as a strength.
You can modify the Subscriber logic by integrating the email service and providing order data. Let's use a trivistotls method instead of retrieve to get the order details.
You can also modify the event name, changing it from the order service events property to a simple strength like order placed.
If you want to see the full list of events available in Medusa, you should visit the events reference in the Medusa documentation. There you will find the comprehensive list of events ranging from cards to product related events.
Now you’ve seen how to set up an order-related subscriber, create a new event handler and customize it to perform actions like sending an email with order details.
In the next episode, which will be the last, we will customize and extend the Medusa Admin dashboard.
We hope you found Viktor's tutorial insightful and helpful.
Welcome to our Medusa Development Course! Explore how loaders work within Medusa core and create a custom loader.
Welcome to our Medusa Development Course! Improve Medusa’s SupplierService by making a few updates, like adding transaction support, handling configurations, and adjusting the service’s behavior.