"Getting started with Sylius" training sessions now available in various cities in Europe!

Blog

Welcome to our blog, where we share news related to Sylius and post about technology & eCommerce.

Bartosz Pietrzak
07.12.2018 | 2 mins read

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!

Bartosz Pietrzak
See my roles

Software developer fond of trying new technologies and challenges. A huge fan of clean code and applying multiple levels of application testing. After hours a keen alternative music listener and a guitarist - that's why you rarely see him without his headphones on. If you want to talk about programming or heavy guitar riffs - you've met a proper person.

Be the first to find out about new posts. Join to our newsletter!