custom/plugins/FuerstenbergPorzellan/src/Subscriber/OrderSubscriber.php line 41

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace FuerstenbergPorzellan\Subscriber;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. class OrderSubscriber implements EventSubscriberInterface
  11. {
  12.      /**
  13.      * @var RequestStack
  14.      */
  15.     private $requestStack;
  16.     /**
  17.      * @var EntityRepository
  18.      */
  19.     private $orderRepository;
  20.     public function __construct(
  21.         RequestStack $requestStack,
  22.         EntityRepository $orderRepository
  23.     )
  24.     {
  25.         $this->requestStack $requestStack;
  26.         $this->orderRepository $orderRepository;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             CheckoutOrderPlacedEvent::class => 'CheckoutOrderPlaced',
  32.         ];
  33.     }
  34.     public function CheckoutOrderPlaced(CheckoutOrderPlacedEvent $event)
  35.     {   
  36.         $request $this->requestStack->getCurrentRequest();
  37.         if ($request !== null) {
  38.             $confirmdatasend $request->request->get('confirmdatasend');
  39.             if ($confirmdatasend !== null) {
  40.                 $order $event->getOrder();
  41.                 $customFields $order->getCustomFields() ?? [];
  42.                 $customFields['lds_checkout_privacy'] = filter_var($confirmdatasendFILTER_VALIDATE_BOOLEAN);
  43.                 $this->orderRepository->upsert([
  44.                     [
  45.                         'id' => $order->getId(),
  46.                         'customFields' => $customFields
  47.                     ]
  48.                 ], $event->getContext());
  49.             }
  50.         }
  51.     }
  52. }