Fellow Sylius developers, please welcome ShopApiPlugin – an API based shop implementation which will make any integration with front-end framework much easier. And it is one of the first official plugins for Sylius that can serve as an example of our extendability.
Apart from the stable release, recently we have been working on one of the most exciting additions to Sylius core platform. And I couldn’t be more happy to finally share this with the Community and improve based on your feedback.
With the ShopApiPlugin, Sylius provides a new way of building eCommerce apps. It doesn’t matter if it is a mobile app, PWA (Progressive Web App) or just a simple Angular/React/VUE.js based website – it’s never been easier.
If you are working on a project or starting a new one with the “classic” Symfony & Twig approach, don’t worry. This new plugin is just one more way to build modern apps and we are still exploring this.
Our recent projects, questions raised on our Slack channels or even the discussions we’ve been part of at various meetups and conferences – all this tells us that we are going in the right direction. **Modern & easy to integrate eCommerce platform with powerful APIs is the future. **
Feature requirements of modern eCommerce websites are constantly growing and it is impossible to satisfy all of them in a single platform. It is much more effective to integrate with the best technologies in category. For example, Akeneo provides an excellent PIM solution. Drupal, eZ or Contentful are all great and fully functional CMSes. Whole companies stand behind these projects and they are very good at what they do. We are the best at handling eCommerce and building developer tools. Let’s integrate all these instead of reinventing the wheel!
We have used the CQS pattern instead of CRUD and handle our logic with command bus. This solution will make it easy to understand and extend. Do you need custom logic? Just override the CommandHandler. The command doesn’t have enough information? You can override the whole controller. But it’s also not a problem because our controllers are mostly less than 100 lines long. Internally we are using same Sylius objects and state machine so nothing changes from the internals perspective. The API shop interface works exactly the same as our standard, Twig-based shop UI.
It is also important to mention about view handling. Each time you would like to query a database to retrieve the data it will go through a set of factories which will build a frontend-developer friendly output. No need to implement too much business logic inside of your front app. Responses will contain calculated prices and translated fields to make its as easy as it is possible to integrate this data into your app.
Let’s have a look at some example requests & responses:
Adding to the cart is as easy as sending a simple POST request:
POST /shop-api/carts/X4325DASD/items/
{
"productCode": "sylius_tshirt",
"quantity": 3,
"options": {
"tshirt_size": "tshirt_size_s",
"tshirt_color": "tshirt_color_black"
}
}
You can get a detailed product information via its slug:
GET /shop-api/products/logan-mug/
{
"code": "LOGAN_MUG_CODE",
"name": "Logan Mug",
"slug": "logan-mug",
"averageRating": 4.5,
"taxons": {
"main": "MAIN_TAXON_CODE",
"others": [
"OTHER_TAXON_CODE"
]
}
...
}
Did I mention, that it is totally fine to run ShopApiPlugin with ShopBundle in parallel?
This blog post is not only an overview of ShopApiPlugin. It is also a request for help. We are very grateful of our community. Without you, we couldn’t be in the place that we are right now. But with ShopApiPlugin we need you one more time. Your feedback about how does it work for you or what should be improved is invaluable. PRs are also more than welcome. So please, help us redefine how eCommerce applications are built. Especially if you are a frontend developer.
If you wonder how does ShopApiPlugin really look like you can check the project’s README and API endpoints documentation.
Keep in mind that unless you are an experienced frontend developer and have built PWA/SPA apps before, the standard Sylius setup is still the recommended way to develop your projects. The plugin will evolve and we are considering introducing GraphQL API variant in the future.
We have a really strong belief that the next-generation eCommerce platform will not be the one with all possible features, but the one that integrates with the best tools in category. And SyliusShopApi plugin is a big step in this direction.