<?php
namespace Customize\EventListener;
use Customize\Service\MailService;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SendNaireAndSeaBurialMailSubscriber implements EventSubscriberInterface
{
public function __construct(
MailService $mailService
) {
$this->mailService = $mailService;
}
public static function getSubscribedEvents(): array
{
return [
EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE => 'onAfterSendOrderMail',
];
}
public function onAfterSendOrderMail(EventArgs $event)
{
$Order = $event->getArgument("Order");
// 注文完了メールより後に送られるようにsleepを実行
sleep(10);
// $Orderに含まれる名入れ商品の数だけsendNaireMailを発火する
foreach ($Order->getOrderItems() as $orderItem) {
if ($orderItem->getNaire()) {
$this->mailService->sendNaireMail($Order, $orderItem);
}
}
$this->mailService->sendSeaBurialMail($Order);
}
}