vendor/store.shopware.com/swagb2bplatform/components/Order/BridgePlatform/AuthAssigner.php line 33

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.     private AuthenticationService $authenticationService;
  12.     private ShopOrderRepositoryInterface $shopOrderRepository;
  13.     public function __construct(
  14.         AuthenticationService $authenticationService,
  15.         ShopOrderRepositoryInterface $shopOrderRepository
  16.     ) {
  17.         $this->authenticationService $authenticationService;
  18.         $this->shopOrderRepository $shopOrderRepository;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             OrderEvents::ORDER_WRITTEN_EVENT => 'setOrderIdentity',
  24.         ];
  25.     }
  26.     public function setOrderIdentity(EntityWrittenEvent $event): void
  27.     {
  28.         if (!$this->authenticationService->isB2b()) {
  29.             return;
  30.         }
  31.         $authId $this->authenticationService
  32.             ->getIdentity()
  33.             ->getOwnershipContext()
  34.             ->authId;
  35.         $debtorId $this->authenticationService
  36.             ->getIdentity()
  37.             ->getOwnershipContext()
  38.             ->shopOwnerUserId;
  39.         foreach ($event->getPayloads() as $payload) {
  40.             if (array_key_exists('orderNumber'$payload)) {
  41.                 $this->shopOrderRepository
  42.                     ->setOrderIdentity((string) $payload['orderNumber'], $authId);
  43.                 $this->shopOrderRepository
  44.                     ->setOrderToShopOwnerUser((string) $payload['orderNumber'], $debtorId);
  45.             }
  46.         }
  47.     }
  48. }