Sylius / InvoicingPlugin

Generate an Invoice for every placed order
MIT License
79 stars 82 forks source link

Send Invoice on Order Placed #130

Open TELLO0815 opened 5 years ago

TELLO0815 commented 5 years ago

I miss the option to send out invoice depending on the payment method. Some need the invoice in advance.

I can not make it running. I guess im just to early, trying to send email before created i guess. Is there any help for me?

app.invoice_send_listener:
    class: App\EventListener\SendInvoiceListener
    arguments: ['sylius_invoicing_plugin.event_bus', 'Sylius\InvoicingPlugin\DateTimeProvider']
<?php

namespace App\EventListener;

use Sylius\InvoicingPlugin\Command\SendInvoiceEmail;
use Sylius\InvoicingPlugin\Event\OrderPlaced;
use Symfony\Component\Messenger\MessageBusInterface;

class SendInvoiceListener
{
    /** @var MessageBusInterface */
    private $commandBus;

    public function __construct(MessageBusInterface $commandBus)
    {
        $this->commandBus = $commandBus;
    }

    public function __invoke(OrderPlaced $event): void
    {
        $this->commandBus->dispatch(new SendInvoiceEmail($event->orderNumber()));
    }
}  
diimpp commented 5 years ago

Simplest solution is to override plugin's listeners services and do your magic inside.

You need to override both or you will send invoice email twice. On OrderPlaced with your custom implementation and on OrderPaid by default listener.

sylius_invoicing_plugin.event_listener.order_placed sylius_invoicing_plugin.listener.order_payment_paid