custom/plugins/WbfkExtensions/src/Subscriber/AttachAccountManagerToOrder.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace WbfkExtensions\Subscriber;
  4. use Shopware\Core\Checkout\Cart\Order\CartConvertedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use WbfkExtensions\Service\CustomerAccountManagerService;
  7. class AttachAccountManagerToOrder implements EventSubscriberInterface
  8. {
  9.     public function __construct(private readonly CustomerAccountManagerService $customerAccountManagerService)
  10.     {
  11.     }
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             CartConvertedEvent::class => 'addAccountManagerToConvertedCart',
  16.         ];
  17.     }
  18.     public function addAccountManagerToConvertedCart(CartConvertedEvent $event): void
  19.     {
  20.         $convertedCart $event->getConvertedCart();
  21.         if (isset($convertedCart['orderCustomer'])) {
  22.             $customerId $convertedCart['orderCustomer']['customerId'];
  23.             $convertedCart['extensions']['wbfkOrderExtension'] = [
  24.                 'assigneeId' => $this->customerAccountManagerService->getAccountManagerId($customerId$event->getContext()),
  25.             ];
  26.             $event->setConvertedCart($convertedCart);
  27.         }
  28.     }
  29. }