src/EventSubscriber/SendConsolidatedInvoiceEventSubscriber.php line 27
<?php
namespace App\EventSubscriber;
use App\Event\SendCodWithdrawalEmailEvent;
use App\Event\SendConsolidatedInvoiceEvent;
use App\Event\SendEmailEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SendConsolidatedInvoiceEventSubscriber implements EventSubscriberInterface
{
public function __construct(private EventDispatcherInterface $eventDispatcher,
private string $fromEmail, private string $fromName)
{
}
public static function getSubscribedEvents()
{
return [
SendConsolidatedInvoiceEvent::NAME => [
['handleSendConsolidatedInvoice', 10]
]
];
}
public function handleSendConsolidatedInvoice(SendConsolidatedInvoiceEvent $event)
{
$consolidatedInvoice = $event->getInvoice();
$attachment = $event->getAttachment();
$customer = $event->getCustomer();
$emailParameters = [
'from' => [
'email' => $this->fromEmail,
'name' => $this->fromName
],
'to' => [
'email' => $customer->getEmail()
],
'subject' => 'Statement and Invoice for '.$consolidatedInvoice->getItems()->first()->getItemName(),
'template' => 'email/consolidated_statement.html.twig',
'parameters' => [
'customer' => $customer,
'itemName' => $consolidatedInvoice->getItems()->first()->getItemName(),
'invoice' => $consolidatedInvoice,
],
'attachment' => $attachment
];
$emailEvent = new SendEmailEvent($emailParameters);
$this->eventDispatcher->dispatch($emailEvent, SendEmailEvent::NAME);
}
}