Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/var/
/vendor/
/node_modules/
/composer.lock
Expand Down
1 change: 1 addition & 0 deletions config/services/generators.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<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>
<argument type="tagged_iterator" tag="sylius_invoicing.modifier.invoice" />
</service>
<service id="Sylius\InvoicingPlugin\Creator\InvoiceCreatorInterface" alias="sylius_invoicing.creator.invoice" />

Expand Down
17 changes: 17 additions & 0 deletions src/Creator/InvoiceCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Sylius\InvoicingPlugin\Generator\InvoiceGeneratorInterface;
use Sylius\InvoicingPlugin\Generator\InvoicePdfFileGeneratorInterface;
use Sylius\InvoicingPlugin\Manager\InvoiceFileManagerInterface;
use Sylius\InvoicingPlugin\Modifier\InvoiceModifierInterface;

final class InvoiceCreator implements InvoiceCreatorInterface
{
Expand All @@ -32,7 +33,17 @@ public function __construct(
private readonly InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator,
private readonly InvoiceFileManagerInterface $invoiceFileManager,
private readonly bool $hasEnabledPdfFileGenerator = true,
private readonly ?iterable $invoiceModifiers = null,
) {
if (null === $this->invoiceModifiers) {
trigger_deprecation(
'sylius/invoicing-plugin',
'2.1',
'Not passing a "%s" to "%s" is deprecated and will be required in Sylius Invoicing Plugin 3.0.',
InvoiceModifierInterface::class,
self::class,
);
}
}

public function __invoke(string $orderNumber, \DateTimeInterface $dateTime): void
Expand All @@ -49,6 +60,12 @@ public function __invoke(string $orderNumber, \DateTimeInterface $dateTime): voi

$invoice = $this->invoiceGenerator->generateForOrder($order, $dateTime);

if (null !== $this->invoiceModifiers) {
foreach ($this->invoiceModifiers as $modifier) {
$invoice = $modifier->modify($invoice);
}
}

if (!$this->hasEnabledPdfFileGenerator) {
$this->invoiceRepository->add($invoice);

Expand Down
21 changes: 21 additions & 0 deletions src/Modifier/InvoiceModifierInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Modifier;

use Sylius\InvoicingPlugin\Entity\InvoiceInterface;

interface InvoiceModifierInterface
{
public function modify(InvoiceInterface $invoice): InvoiceInterface;
}