Skip to content

Conversation

@tomkalon
Copy link

@tomkalon tomkalon commented Oct 23, 2025

Q A
Branch? 3.0
Bug fix? no
New feature? yes
BC breaks? yes
License MIT

UPGRADE FROM 2.2 TO 3.0

Depend on: #395 PR

Changes

  1. Persisted PDF path on Invoice:
  • Added to Invoice new path field (unique) storing the final PDF location (e.g. annually/2025_10_000000001.pdf).
  1. Filename generation moved from InvoiceCreator to InvoiceFactory.

InvoiceCreator no longer generates PDFs at creation time.

PDFs are generated on first provide/download via the provider.

<service id="sylius_invoicing.custom_factory.invoice" class="Sylius\InvoicingPlugin\Factory\InvoiceFactory">
    <argument>%sylius_invoicing.model.invoice.class%</argument>
    <argument type="service" id="sylius_invoicing.factory.shop_billing_data" />
+   <argument type="service" id="sylius_invoicing.generator.invoice_file_name" />
</service>
<service id="sylius_invoicing.creator.invoice" class="Sylius\InvoicingPlugin\Creator\InvoiceCreator">
    <argument type="service" id="sylius_invoicing.repository.invoice" />
    <argument type="service" id="sylius.repository.order" />
    <argument type="service" id="sylius_invoicing.generator.invoice" />
-   <argument type="service" id="sylius_invoicing.generator.invoice_pdf_file" />
-   <argument type="service" id="sylius_invoicing.manager.invoice_file" />
-   <argument>%sylius_invoicing.pdf_generator.enabled%</argument>
</service>
  1. InvoiceFactory now depends on InvoiceFileNameGeneratorInterface.
<service id="sylius_invoicing.custom_factory.invoice" class="Sylius\InvoicingPlugin\Factory\InvoiceFactory">
    <argument>%sylius_invoicing.model.invoice.class%</argument>
    <argument type="service" id="sylius_invoicing.factory.shop_billing_data" />
+   <argument type="service" id="sylius_invoicing.generator.invoice_file_name" />
</service>

On creation, it calls:

$fileName = $invoiceFileNameGenerator->generateForPdf($number);

and passes it to the Invoice constructor as $path.

  1. InvoiceFileProvider is now the primary orchestrator of PDF generation

Removed InvoiceFileNameGeneratorInterface from InvoiceFileProvider.

Added sylius_invoicing.pdf_generator.enabled parameter to constructor.

<service id="sylius_invoicing.provider.invoice_file" class="Sylius\InvoicingPlugin\Provider\InvoiceFileProvider">
-   <argument type="service" id="sylius_invoicing.generator.invoice_file_name" />
    <argument type="service" id="gaufrette.sylius_invoicing_invoice_filesystem" />
    <argument type="service" id="sylius_invoicing.generator.invoice_pdf_file" />
    <argument type="service" id="sylius_invoicing.manager.invoice_file" />
    <argument>%sylius_invoicing.invoice_save_path%</argument>
+   <argument>%sylius_invoicing.pdf_generator.enabled%</argument>
</service>
  1. InvoiceFileNameGenerator signature & scoping

BC break: generateForPdf() now accepts string $invoiceNumber (not InvoiceInterface).

// before:
public function generateForPdf(InvoiceInterface $invoice): string;

// after:
public function generateForPdf(string $invoiceNumber): string;
  1. Can prefix filenames based on SYLIUS_INVOICING_SEQUENCE_SCOPE:

global (default): no prefix

monthly: monthly/…

annually: annually/…

  1. InvoicePdfFileGenerator simplified:
  • Removed dependency on InvoiceFileNameGeneratorInterface.

  • Uses Invoice::path() as the filename:

<service id="sylius_invoicing.generator.invoice_pdf_file" class="Sylius\InvoicingPlugin\Generator\InvoicePdfFileGenerator">
    <argument type="service" id="sylius_invoicing.generator.twig_to_pdf" />
    <argument type="service" id="file_locator" />
-   <argument type="service" id="sylius_invoicing.generator.invoice_file_name" />
    <argument>@SyliusInvoicingPlugin/shared/download/pdf.html.twig</argument>
    <argument>%sylius_invoicing.template.logo_file%</argument>
</service>
$filename = $invoice->path();

@tomkalon tomkalon force-pushed the feature/refactoring branch from b93c456 to ed09c91 Compare October 23, 2025 11:55
@tomkalon tomkalon force-pushed the feature/refactoring branch 2 times, most recently from 40353be to fdee193 Compare October 23, 2025 13:33
@tomkalon tomkalon force-pushed the feature/refactoring branch from fdee193 to fece09a Compare October 24, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant