app/Customize/EventListener/OrderDeliveredSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace Customize\EventListener;
  3. use Customize\Service\ReferralCouponService;
  4. use Eccube\Entity\Master\OrderStatus;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Workflow\Event\Event;
  7. class OrderDeliveredSubscriber implements EventSubscriberInterface
  8. {
  9.     private ReferralCouponService $referralCouponService;
  10.     public function __construct(ReferralCouponService $referralCouponService)
  11.     {
  12.         $this->referralCouponService $referralCouponService;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             'workflow.order.completed' => ['onWorkflowCompleted'],
  18.         ];
  19.     }
  20.     public function onWorkflowCompleted(Event $event): void
  21.     {
  22.         log_info("[onWorkflowCompleted]");
  23.         $context $event->getSubject();
  24.         $Order   $context->getOrder();
  25.         log_info((int) $context->getStatus());
  26.         if ((int) $context->getStatus() !== OrderStatus::DELIVERED) {
  27.             return;
  28.         }
  29.         
  30.         log_info("配送済みに変更されました。紹介者にクーポンを発行を開始します。", [$Order->getId()]);
  31.         $coupon $this->referralCouponService->generateReferrerCouponFromReferee($Order->getCustomer());
  32.         if ($coupon) {
  33.             log_info('紹介者向けクーポンを発行しました', [
  34.                 'order_id'      => $Order->getId(),
  35.                 'referrer_id' => $coupon->getId(),
  36.                 'coupon_cd'     => $coupon->getCouponCd(),
  37.             ]);
  38.         }
  39.     }
  40. }