Invoice PDF Upload
After posting a sales order in BC, the BC invoice is automatically uploaded to Shopware as a PDF and attached to the order as a document.
Workflow
Post Sales Order (BC)
|
| OnAfterPostSalesDoc (Sales-Post)
| → Shopware Order ID present
v
Sync Buffer (SyncType = InvoicePDF)
|
| Job Queue: PrepareInvoicePDFSyncEntries
v
Trans. Log (Functionname='InvoicePDFSync')
|
| Job Queue: ProcessInvoicePDFSyncEntries
v
Step 1: POST /api/_action/order/document/invoice/create
|
| → documentId
v
Step 2: POST /api/_action/document/{documentId}/upload
(PDF binary data, Content-Type: application/octet-stream)
Prerequisites
- The sales order must have a Shopware Order ID (i.e. it was created via the order import from Shopware)
- The posted invoice must be printable using the standard invoice report (Standard Sales - Invoice, Report 1306)
Behaviour
The feature is fully automatic — no additional setup steps are required. As soon as a Shopware order is posted in BC:
- The
OnAfterPostSalesDocsubscriber detects the Shopware Order ID - An entry is created in the sync buffer (deduplicated: one entry per order)
PrepareInvoicePDFSyncEntries(Job Queue) moves the entry to the transaction logProcessInvoicePDFSyncEntries(Job Queue) performs the two-step upload:- Step 1: Creates a document entry in Shopware with
_static: true. Shopware reserves a UUID (documentId) for the external document. - Step 2: Generates the PDF from the BC invoice report and uploads the binary data under the documentId.
- Step 1: Creates a document entry in Shopware with
The PDF then appears in Shopware under Documents on the order and can be downloaded there.
Job Queue Entries
| Parameter | Description |
|---|---|
PrepareInvoicePDFSyncEntries |
Sync buffer → transaction log |
ProcessInvoicePDFSyncEntries |
Generate PDF + upload to Shopware in two steps |
Full reference of all job queue entries: Job Queue Reference
These entries are created automatically by the Setup Wizard.
Technical Details
Shopware Document API
| Step | Endpoint | Description |
|---|---|---|
| 1 | POST /api/_action/order/document/invoice/create |
Create document entry (_static: true = external PDF) |
| 2 | POST /api/_action/document/{documentId}/upload?fileName={invoiceNo}&extension=pdf |
Upload PDF binary data |
Important
The _static: true field in Step 1 is mandatory. Without it, Shopware rejects the PDF upload with the error "Unable to generate document. This document is dynamically generated and cannot be overwritten".
PDF Generation in BC
The PDF is generated using Report.SaveAs(Report::"Standard Sales - Invoice", ...). The report is executed with a filter on the posted invoice so that only that specific invoice is included in the PDF.
Error Handling
If either step fails, the error is stored in the transaction log. The entry remains in Error state and is not retried on the next Job Queue run. The Max Batch Size from the Shopware Setup is respected.