custom/plugins/SwagB2bPlatform/components/OrderNumber/BridgePlatform/OrderNumberCheckoutSubscriber.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\B2B\OrderNumber\BridgePlatform;
  3. use Shopware\B2B\StoreFrontAuthentication\Framework\AuthenticationService;
  4. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class OrderNumberCheckoutSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var AuthenticationService
  10.      */
  11.     private $authenticationService;
  12.     public function __construct(
  13.         AuthenticationService $authenticationService
  14.     ) {
  15.         $this->authenticationService $authenticationService;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             CheckoutOrderPlacedEvent::class => 'updateProductNumbersWithCustomOrderNumbersForOrderConfirmMail',
  21.         ];
  22.     }
  23.     public function updateProductNumbersWithCustomOrderNumbersForOrderConfirmMail(CheckoutOrderPlacedEvent $event): void
  24.     {
  25.         if (!$this->authenticationService->isB2b()) {
  26.             return;
  27.         }
  28.         foreach ($event->getOrder()->getLineItems() as $lineItem) {
  29.             $payload $lineItem->getPayload();
  30.             if (!isset($payload[OrderNumberCartProcessor::B2B_ORDER_NUMBER_PAYLOAD_KEY])) {
  31.                 continue;
  32.             }
  33.             $payload['productNumber'] = $payload[OrderNumberCartProcessor::B2B_ORDER_NUMBER_PAYLOAD_KEY];
  34.             $lineItem->setPayload($payload);
  35.         }
  36.     }
  37. }