custom/plugins/TigerRequestDeliveryDate/src/Subscriber/CartConvertedSubscriber.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TigerMedia\General\TigerRequestDeliveryDate\Subscriber;
  3. use Shopware\Core\Checkout\Cart\Order\CartConvertedEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. class CartConvertedSubscriber implements EventSubscriberInterface
  9. {
  10.     private RequestStack $requestStack;
  11.     public function __construct(RequestStack $requestStack)
  12.     {
  13.         $this->requestStack $requestStack;
  14.     }
  15.     public static function getSubscribedEvents()
  16.     {
  17.         return [
  18.             CartConvertedEvent::class => 'orderWritten',
  19.         ];
  20.     }
  21.     public function orderWritten(CartConvertedEvent $event): void
  22.     {
  23.         $orderData $event->getConvertedCart();
  24.         $orderCustomFields $orderData['customFields'] ?? [];
  25.         $requestedDeliveryDate $this->requestStack->getCurrentRequest()->request->get('requestDeliveryDate');
  26.         if ($requestedDeliveryDate) {
  27.             $orderCustomFields['tigermediarequestdelivery'] = 
  28. $requestedDeliveryDate;
  29.         }
  30.         $orderData['customFields'] = $orderCustomFields;
  31.         $event->setConvertedCart($orderData);
  32.     }
  33. }