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
Business News Technical 3 min read 28.09.2020
Get ready for global sales & operations with the most advanced payment solution from the famous fintech giant, now available in Sylius out of the box. Read More
Business News 3 min read 14.09.2020
We proudly present to you the latest version of the Sylius eCommerce Platform – 1.8, which comes with a brand new, unified API powered by API Platform, Loyalty points system for Sylius Plus, and as you can probably see, a brand new sylius.com website! Numbers This new release is a… Read More
Business Ecosystem News 3 min read 13.08.2020
Read why the French market leader trusted Sylius in a strategic re-platforming process to get a competitive eCommerce advantage. Read More
Comments