2 min. read
Categories: Technical
How to issue an invoice in Sylius?

All aboard the plugin train! What if once you have ordered some products and completed the payment process you would receive an email with a pdf document as a proof of placing the order? What’s more, this file would also contain both your and shop’s name, address and company. Does this dataset sound familiar? That’s right – here comes the Invoicing Plugin!

What is Invoicing Plugin?

Invoicing plugin is one of several Sylius extensions developed by Sylius Core Team. It reflects a significant amount of business features that are listed below:

  • Creating an invoice automatically once the checkout process is completed
  • An invoice providing data on the customer and the company (name, billing data)
  • Browsing and filtering invoices in the administration panel
  • Downloading invoices as pdf files by both customer and administrator
  • Sending an invoice to the customer via email once an order is paid
  • Resending an invoice to the customer from admin panel
  • Setting shop billing data globally on channel

How does it work code-wise?

All magic included in Invoicing Plugin source code begins where custom post-insert event listener receives an order in the completed state. What happens next? Let me describe the main plugin logic in a few steps:

  • The event listener receives an instance of order in the completed state
  • The event listener dispatches OrderPlacedEvent
  • The event is caught by CreateInvoiceOnOrderPlacedListener
  • Order’s data is transformed into invoice-related models, i.e. Address into BillingData or OrderItem into LineItem
  • Previously prepared data is set on the newly created invoice and inserted into the database
  • Since Invoice class is a Resource, now the invoice is visible and editable in the Admin panel
  • Once the order is paid, the invoice is sent to the customer via email as a pdf file
  • The document can be sent to the customer manually by an administrator any time

A lot of Sylius plugins are based on the concept of Resource and Invoicing Plugin is not an exception in that matter. Thus, the plugin’s configuration is split between config.yml and routing.yml files. Custom actions such as sending an invoice email or downloading the document as pdf file are driven by single action controllers.

How to get it?

It’s free! Try it out by visiting the plugin’s repository and following a few simple installation steps. Like any other official Sylius plugin, Invoicing Plugin offers two ways of installation – manual one and based on Symfony Flex. See which solution is more tailored to your needs and then require the package by Composer. As usual, if you come up with an opinion or idea that will help us make the plugin even more valuable, let us know. But for now…

Happy invoicing!

Share:
More from our blog
Technical 2 min read 04.12.2024
Here’s everything you had to know about the first major release since 2017! Over 7 years after the first major release, on Nov 12, 2024, we have released Sylius 2.0.0. We had a great opportunity to announce it first at SyliusCon in Lyon, but now, as we are back to… Read More
2 min read 22.11.2024
The emotions start to settle after SyliusCon, and it’s time to reflect on this incredible milestone in our journey. Why a milestone? Because SyliusCon exceeded our expectations in every possible way. We broke attendance records and brought together the key figures of our community, numerous partners, freelancers, and simply all… Read More
Cloud 2 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
Comments