custom/plugins/EnetPickupDate/src/Subscriber/CheckoutSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. namespace EnetPickupDate\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. class CheckoutSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var EntityRepository
  11.      */
  12.     protected $orderRepository;
  13.     /** @var RequestStack  */
  14.     protected $requestStack;
  15.     public function __construct(EntityRepository $orderRepositoryRequestStack $requestStack)
  16.     {
  17.         $this->orderRepository $orderRepository;
  18.         $this->requestStack $requestStack;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             CheckoutOrderPlacedEvent::class => 'onCheckoutOrderPlaced'
  24.         ];
  25.     }
  26.     public function onCheckoutOrderPlaced(CheckoutOrderPlacedEvent $event): void
  27.     {
  28.         $order $event->getOrder();
  29.         if(!$order) {
  30.             return;
  31.         }
  32.         $request $this->requestStack->getCurrentRequest()->request;
  33.         $pickup $request->get('enet_pickup');
  34.         if(isset($pickup['date']) && isset($pickup['time'])) {
  35.             $pickupDate $pickup['date'];
  36.             $pickupTime $pickup['time'];
  37.             $this->orderRepository->update([
  38.                [
  39.                    'id' => $order->getid(),
  40.                    'customFields' => ['enet_pickupdate' => $pickupDate .'|'$pickupTime]
  41.                ]
  42.            ], $event->getContext());
  43.         }
  44.     }
  45. }