<?php
declare(strict_types=1);
namespace WbfkExtensions\Subscriber;
use Shopware\Core\Checkout\Cart\Order\CartConvertedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use WbfkExtensions\Service\CustomerAccountManagerService;
class AttachAccountManagerToOrder implements EventSubscriberInterface
{
public function __construct(private readonly CustomerAccountManagerService $customerAccountManagerService)
{
}
public static function getSubscribedEvents(): array
{
return [
CartConvertedEvent::class => 'addAccountManagerToConvertedCart',
];
}
public function addAccountManagerToConvertedCart(CartConvertedEvent $event): void
{
$convertedCart = $event->getConvertedCart();
if (isset($convertedCart['orderCustomer'])) {
$customerId = $convertedCart['orderCustomer']['customerId'];
$convertedCart['extensions']['wbfkOrderExtension'] = [
'assigneeId' => $this->customerAccountManagerService->getAccountManagerId($customerId, $event->getContext()),
];
$event->setConvertedCart($convertedCart);
}
}
}