We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is this possible to achieve this by overriding the default behavior of the state machine https://github.com/Sylius/InvoicingPlugin#extension-points
or I would need to override classes and extend the plugin myself?
The text was updated successfully, but these errors were encountered:
I did like this:
service.yml
app.listener.send_invoice_on_order: class: App\EventListener\SendInvoiceOnOrderListener arguments: ['@sylius_invoicing_plugin.creator.invoice', '@sylius_invoicing_plugin.custom_repository.invoice', '@sylius_invoicing_plugin.email.invoice_email_sender', '@sylius.repository.order'] tags: - { name: messenger.message_handler, event: sylius_invoicing_plugin.event_bus }
<?php declare(strict_types=1); namespace App\EventListener; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\InvoicingPlugin\Creator\InvoiceCreatorInterface; use Sylius\InvoicingPlugin\Email\InvoiceEmailSenderInterface; use Sylius\InvoicingPlugin\Entity\InvoiceInterface; use Sylius\InvoicingPlugin\Event\OrderPlaced; use Sylius\InvoicingPlugin\Exception\InvoiceAlreadyGenerated; use Sylius\InvoicingPlugin\Repository\InvoiceRepository; final class SendInvoiceOnOrderListener { /** @var InvoiceCreatorInterface */ private $invoiceCreator; /** @var InvoiceRepository */ private $invoiceRepository; /** @var OrderRepositoryInterface */ private $orderRepository; /** @var InvoiceEmailSenderInterface */ private $invoiceEmailSender; public function __construct( InvoiceCreatorInterface $invoiceCreator, InvoiceRepository $invoiceRepository, InvoiceEmailSenderInterface $invoiceEmailSender, OrderRepositoryInterface $orderRepository ) { $this->invoiceCreator = $invoiceCreator; $this->invoiceRepository = $invoiceRepository; $this->invoiceEmailSender = $invoiceEmailSender; $this->orderRepository = $orderRepository; } public function __invoke(OrderPlaced $event): void { try { $this->invoiceCreator->__invoke($event->orderNumber(), $event->date()); } catch (InvoiceAlreadyGenerated $exception) { return; } /** @var InvoiceInterface $invoice */ $invoice = $this->invoiceRepository->findOneByOrderNumber($event->orderNumber()); /** @var OrderInterface $order */ $order = $this->orderRepository->findOneBy(['number' => $event->orderNumber()]); /** @var CustomerInterface $customer */ $customer = $order->getCustomer(); $this->invoiceEmailSender->sendInvoiceEmail($invoice, $customer->getEmail()); } }
Sorry, something went wrong.
No branches or pull requests
Is this possible to achieve this by overriding the default behavior of the state machine https://github.com/Sylius/InvoicingPlugin#extension-points
or I would need to override classes and extend the plugin myself?
The text was updated successfully, but these errors were encountered: