2222use Sylius \InvoicingPlugin \Generator \InvoiceGeneratorInterface ;
2323use Sylius \InvoicingPlugin \Generator \InvoicePdfFileGeneratorInterface ;
2424use Sylius \InvoicingPlugin \Manager \InvoiceFileManagerInterface ;
25+ use Sylius \InvoicingPlugin \Modifier \InvoiceModifierInterface ;
2526
2627final class InvoiceCreator implements InvoiceCreatorInterface
2728{
@@ -32,7 +33,17 @@ public function __construct(
3233 private readonly InvoicePdfFileGeneratorInterface $ invoicePdfFileGenerator ,
3334 private readonly InvoiceFileManagerInterface $ invoiceFileManager ,
3435 private readonly bool $ hasEnabledPdfFileGenerator = true ,
36+ private readonly ?iterable $ invoiceModifiers = null ,
3537 ) {
38+ if (null === $ this ->invoiceModifiers ) {
39+ trigger_deprecation (
40+ 'sylius/invoicing-plugin ' ,
41+ '2.1 ' ,
42+ 'Not passing a "%s" to "%s" is deprecated and will be required in Sylius Invoicing Plugin 3.0. ' ,
43+ InvoiceModifierInterface::class,
44+ self ::class,
45+ );
46+ }
3647 }
3748
3849 public function __invoke (string $ orderNumber , \DateTimeInterface $ dateTime ): void
@@ -49,6 +60,12 @@ public function __invoke(string $orderNumber, \DateTimeInterface $dateTime): voi
4960
5061 $ invoice = $ this ->invoiceGenerator ->generateForOrder ($ order , $ dateTime );
5162
63+ if (null !== $ this ->invoiceModifiers ) {
64+ foreach ($ this ->invoiceModifiers as $ modifier ) {
65+ $ invoice = $ modifier ->modify ($ invoice , $ order );
66+ }
67+ }
68+
5269 if (!$ this ->hasEnabledPdfFileGenerator ) {
5370 $ this ->invoiceRepository ->add ($ invoice );
5471
0 commit comments