<?php
namespace App\EventListener;
use App\Component\Configuration\Util\Config;
use App\Entity\Order;
use App\Event\SubmitOrderEvent;
use App\Sendgrid\MailerInterface;
use App\Util\StringToEntityUtil;
use Gedmo\Translatable\TranslatableListener;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class OrderListener extends FormSubmitEventListener
{
/**
* OrderListener constructor.
*/
public function __construct(
MailerInterface $mailer,
ParameterBagInterface $parameterBag,
StringToEntityUtil $stringToEntityUtil,
?TranslatableListener $translatableListener,
Config $config
) {
parent::__construct($mailer, $parameterBag, $stringToEntityUtil, $translatableListener, $config);
}
public function postOrderSubmit(SubmitOrderEvent $event)
{
$order = $event->getOrder();
switch ($order->getType()) {
case Order::ORDER_TYPE_SAMPLE:
$mail = $this->getMail('site_order_sample_mail');
break;
default:
$mail = $this->getMail('site_order_invoice_mail');
break;
}
if (!$mail) {
return;
}
$this->mailer->mail(
$mail,
$this->getCompanyEmailSender(),
[$order->getEmail()],
['order' => $order]
);
$this->mailer->mail(
$mail,
$this->getCompanyEmailSender(),
[$this->getCompanyEmailaddress()],
['order' => $order]
);
}
}