custom/plugins/SwagB2bPlatform/components/Order/BridgePlatform/AuthAssigner.php line 39

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\B2B\Order\BridgePlatform;
  3. use Shopware\B2B\Order\Framework\ShopOrderRepositoryInterface;
  4. use Shopware\B2B\StoreFrontAuthentication\Framework\AuthenticationService;
  5. use Shopware\Core\Checkout\Order\OrderEvents;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use function array_key_exists;
  9. class AuthAssigner implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var AuthenticationService
  13.      */
  14.     private $authenticationService;
  15.     /**
  16.      * @var ShopOrderRepositoryInterface
  17.      */
  18.     private $shopOrderRepository;
  19.     public function __construct(
  20.         AuthenticationService $authenticationService,
  21.         ShopOrderRepositoryInterface $shopOrderRepository
  22.     ) {
  23.         $this->authenticationService $authenticationService;
  24.         $this->shopOrderRepository $shopOrderRepository;
  25.     }
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             OrderEvents::ORDER_WRITTEN_EVENT => 'setOrderIdentity',
  30.         ];
  31.     }
  32.     public function setOrderIdentity(EntityWrittenEvent $event): void
  33.     {
  34.         if (!$this->authenticationService->isB2b()) {
  35.             return;
  36.         }
  37.         $authId $this->authenticationService
  38.             ->getIdentity()
  39.             ->getOwnershipContext()
  40.             ->authId;
  41.         $debtorId $this->authenticationService
  42.             ->getIdentity()
  43.             ->getOwnershipContext()
  44.             ->shopOwnerUserId;
  45.         foreach ($event->getPayloads() as $payload) {
  46.             if (array_key_exists('orderNumber'$payload)) {
  47.                 $this->shopOrderRepository
  48.                     ->setOrderIdentity((string) $payload['orderNumber'], $authId);
  49.                 $this->shopOrderRepository
  50.                     ->setOrderToShopOwnerUser((string) $payload['orderNumber'], $debtorId);
  51.             }
  52.         }
  53.     }
  54. }