What is a plugin?
A plugin, in other words, an extension to the basic version of an application, Sylius in our case, which adds new or changes the default behavior, introduces new features, or, for example, changes the appearance of some elements. The main difference between a plugin and a traditional implementation is portability. The plugin focuses on a specific problem we encounter over and over and introduces a solution that we can implement quickly in many other applications. Most plugins are created with the customer in mind to make the shopping path even easier.
Creating plugins is also a great idea to show the world what ideas you have developed.
It all starts with an idea
If you are reading this article, you are probably already familiar with Sylius and its basic functionality. You may have been decorating models, forms, or other elements and it’s time to share your ideas with the world. Before you proceed and start developing your own plugin, answer a few questions for yourself:
- Will it be generic? (Can other users install your plugin easily, without modifying core application?)
- Whether it’s useful? (Will it help other people to solve their problem, or is it specific only for your shop?)
- Does it have specific goals? (Plugin must focus on a specific problem?)
What kind of plugin can you build?
In general, all the modifications that we can make in a full application can be done in a plugin. The difference is that a plugin is portable and limited to perform limited tasks and should be adaptable in other instances seamlessly and possibly without conflicts.
For instance, you can build a shipping/payment integration plugin, a content manager, or maybe some other solution you use for your applications which you and other developers have to repeat. Be creative.
Before building your own plugin, to have a better view, it’s a good idea to look at plugins that have already been built and officially approved by Sylius.
Sylius plugins (click on the name to see the plugin on GitHub):
Creating a plugin
Full instructions for installing the plugin can be found in the Sylius documentation, but in a nutshell, it looks like this:
The easiest way to get started with the Sylius plugin is to type the command:
$ composer create-project sylius/plugin-skeleton SyliusMyFirstPlugin
In this simple manner, we have created the skeleton of our plugin. Looking through the directory structure you will quickly realize that it looks very similar to standard Sylius Skeleton.
Apart from that, notice the tests/Application directory – that’s right, here’s a miniature Sylius application that will allow you to test the plugin inside, without installation.
How to start
All you need to do is change the namespaces to match your assumptions. See the documentation for more information, and you are ready to go!
BDD first set up tasks/scenarios and then write functions
Creating a plugin is more than a standalone job. It is also a responsibility for what you have created. Help others understand how your application works. Test every feature.
For your plugin to be officially accepted, it should clearly define its purpose, be properly tested, be installable, and of course, well documented. For more details, visit Sylius documentation. It’s worth answering the question: why should I actually create a plugin – yet, I can implement new features directly in my application? Well, there are many reasons for that:
- Creating plugins makes it possible to transfer functionality to subsequent applications, you never know when it will be useful again.
- By creating a plugin and making it publicly available as open source, you can count on contribution, it’s very likely that in parallel someone else was working on a similar solution, can add interesting ideas and maybe your plugin will become really good.
- By building a plugin you have an incredible chance to build your own brand, be a recognized and acknowledged expert Sylius researcher.
- You can participate in building Sylius right now!
- Who knows? Maybe some serious company (like BitBag) will notice you and you will get a huge opportunity to develop your career.
As you can see, creating a plugin for Sylius is not complicated at all. Start by reviewing already existing plugins that have been approved. Get inspired. Create a skeleton application and start writing. Remember to set goals and test everything. Start developing Sylius together with us! Any troubles? Contact us!