3 min. read
Categories: Business News Technical
Customer Reorder Plugin

Hello everyone! With this blog post, I would like to shortly unveil the approach that we as the Sylius team adapted during new features development and introduce some effects of our work.

Introduction

Recently it’s been a good time for Sylius when it comes to the platform’s development.

What’s crucial about our approach when creating new functionalities is that we have decided to develop and release the majority of features as plugins.

What does it mean for the community? First of all, it makes Sylius even more customizable. Why is that? Well, developing and sharing a plugin is not related to Sylius release cycle. What’s more, if a feature is not desirable in your shop you don’t have to look at the code in order to exclude it from any of business processes. Secondly, using each of the plugins developed by the Sylius Team is intended to be as easy as possible. Thirdly, we all are advocates of “safe enough to try” motto. Merging any plugin with the core Sylius platform shouldn’t take more than just a few moments.

Here is a short, non-technical guide for installing plugins developed by Sylius Team:

  • Add plugin to Sylius-Standard project dependencies
  • Follow instructions defined in README.md file (usually 2-3 steps)
  • Enjoy new Sylius feature

Apart from testing each plugin separately in an isolated environment, we have also decided to check how they cooperate with each other once a new release of any plugin is published. Although we were sure about business value delivered by every feature, we wanted to make sure that possible conflicts between independent pieces of code are resolved in the sandbox environment.

What is Customer Reorder Plugin?

One of the developed and released plugins is Customer Reorder Plugin. It allows the customer to reorder a previously placed order under certain conditions.

Screenshot showing the customer's orders page with reorder buttons

Since Reorder button appeared in Actions section and Order is a Resource, both button template and action configuration are defined in config.yml file placed in plugin source code. What is of vital importance is the declaration of CustomerReorderAction and its __invoke() method executed after clicking the Reorder button. Here all the magic happens.

How does it work?

Reordering is divided into two separate actions – reorder processing and reorder eligibility checking. The former provides data such as order items, billing address or currency and sets them on the newly created reorder. On the other hand, the latter’s responsibility is to check if there are any differences between previously placed order and the reorder. Sounds incoherent? Let me explain the idea on an example.

Let’s assume that one of the shop’s users ordered 2 T-shirts, 2 mugs and a Christmas discount was applied. Now, after a few months, the user wants to place an order containing the same items. However, Christmas discount is not enabled anymore, mugs in the desired variant are no longer available, there is only one T-shirt in stock and its price has changed. A lot of changes, huh?

Indeed, the user should be informed about all these issues. Of course, since the Christmas discount is no longer enabled, it will not be applied. What’s more, reorder items’ list will look like this:

  • One remaining T-Shirt with different price
  • No mugs

Owing to the differences mentioned above, the user should be aware of the following facts:

  • The promotion was not applied
  • There are no mugs in stock
  • There is only one T-Shirt in stock
  • The price of the T-Shirt has changed
  • The total price of the order has probably changed

Here comes reorder eligibility checking. This process works like an ordering comparator – it takes both previously placed order and the reorder and looks for differences between them. All facts mentioned above will be caught by checkers and eventually turned into flash messages displayed on a cart summary view, which is presented in the following screenshot.

Both reorder processing and reorder eligibility checkers are based on Compiler Pass concept delivered by Symfony and extended in Sylius by PrioritizedCompositeServicePass class. All classes that implement ReorderProcessor or ReorderEligibilityChecker are configured to be injected into a container and added to PriorityQueues in order to execute them sequentially.

How to get it?

To sum up, it’s one of several attempts to deliver new Sylius features using a plugin approach. Like the whole Sylius platform, Customer Reorder Plugin is open-source, so you can clone or fork the repository in a second. We would like to encourage you to share your opinions regarding plugins in the context of Sylius and Customer Reorder Plugin itself.

Happy reordering!

Tags:
Share:
More from our blog
Cloud 3 min read 17.06.2024
We are thrilled to announce that we just signed a strategic partnership with Platform.sh, and as a result, we are extending our offer with Sylius Cloud powered by Platform.sh. Platform.sh is a modern Platform-as-a-Service (PaaS) solution that allows businesses to leverage the cloud environment without losing access to the code… Read More
Technical 3 min read 11.06.2024
Abstract 1.12 released in Q4 2022 1.13 on Apr 23rd, 2024 (a year later than we anticipated while releasing 1.12) 3859 commits 23 contributors A stabilized Sylius API powered by API Platform It’s been a long and bumpy road. Having it behind our backs was a highway that led Sylius… Read More
Business Ecosystem News 3 min read 06.06.2024
Welcome to the May summary! As an open-source eCommerce framework, Sylius continues to evolve with significant contributions from our vibrant community and valuable product updates. Apart from describing the technical changes, we will also quickly summarize the Sylius Technical Fundamentals & Sylius Polish Community Meetup and eCommerce Day Kaunas, as… Read More
Comments