Sylius Invoicing Plugin

The Invoicing Plugin provides automated invoice generation and PDF export capabilities for Sylius-based eCommerce systems. It seamlessly integrates into the order lifecycle, offering a standardized and extensible solution for order invoicing.


Key Features

  • Automatic Invoice Generation: Invoices are automatically created when an order reaches a specific state (e.g., created).

  • PDF Invoice Creation: Generates standardized PDF invoice documents using wkhtmltopdf.

  • Customer and Admin Access: Enables invoice PDF download links in both Admin and Shop interfaces.

  • Immutable Invoice Records: Once generated, invoices are stored and remain unchanged, fulfilling compliance and audit requirements.

  • Customizable Storage: Configure where and how invoices are saved on the server.

  • Extensibility: Offers multiple extension points via Symfony events and services.


How It Works

  • The plugin listens for order state transitions.

  • Upon reaching the created state (or another configured one), an invoice is generated.

  • PDF invoices are saved and linked to the corresponding order.

  • Users can download the invoice from their order view.

Configuration Options

Option

Description

pdf_generator.enabled

Enable/disable PDF output

invoice_save_path

Directory path for storing PDF invoices

Extension Points

  • Invoice File Provider: Customize invoice storage lookup logic.

  • Event Listeners: Listen to and react to invoice lifecycle events.

  • Twig Templates: Override layout and content of invoice PDFs.

  • Admin UI: Extend or modify invoice grids and listings.

Example Using Symfony’s Workflow

Here is an example using Symfony’s workflow:

<service id="sylius_invoicing_plugin.event_listener.workflow.payment.produce_order_payment_paid"
         class="Sylius\InvoicingPlugin\EventListener\Workflow\Payment\ProduceOrderPaymentPaidListener">
    <argument type="service" id="sylius_invoicing_plugin.event_producer.order_payment_paid" />

    <tag name="kernel.event_listener" event="workflow.sylius_payment.completed.complete" priority="100" />
</service>

Invoice as a Resource

Additionally, the Invoice model is treated as a Resource.

Defining the Invoice List Template

The template for displaying the list of Invoices is defined in the routing.yml file:

sylius_invoicing_invoice:
    resource: |
        alias: sylius_invoicing.invoice
        section: admin
        templates: "@SyliusAdmin\\Crud"
        only: ['index']
        grid: sylius_invoicing_invoice
        permission: true
        vars:
            all:
                subheader: sylius_invoicing.ui.manage_invoices
            index:
                icon: inbox
    type: sylius.resource

Admin Features

  • Browse all generated invoices.

  • Download invoice PDFs.

  • View invoices linked to specific orders.

Shop Features

  • Customers can access and download invoices for their completed orders.

CLI Tools

  • Generate missing invoices:

bin/console sylius-invoicing:generate-invoices

Troubleshooting

  • Invoice not generated: Ensure the order reached the configured state.

  • PDF not created: Check wkhtmltopdf path and permissions.

  • Missing download links: Confirm templates are not overridden incorrectly.

Resources

Last updated

Was this helpful?