vendor/store.shopware.com/swagb2bplatform/components/OrderNumber/BridgePlatform/OrderNumberCheckoutSubscriber.php line 26

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.     private AuthenticationService $authenticationService;
  9.     public function __construct(
  10.         AuthenticationService $authenticationService
  11.     ) {
  12.         $this->authenticationService $authenticationService;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             CheckoutOrderPlacedEvent::class => 'updateProductNumbersWithCustomOrderNumbersForOrderConfirmMail',
  18.         ];
  19.     }
  20.     public function updateProductNumbersWithCustomOrderNumbersForOrderConfirmMail(CheckoutOrderPlacedEvent $event): void
  21.     {
  22.         if (!$this->authenticationService->isB2b()) {
  23.             return;
  24.         }
  25.         foreach ($event->getOrder()->getLineItems() as $lineItem) {
  26.             $payload $lineItem->getPayload();
  27.             if (!isset($payload[OrderNumberCartProcessor::B2B_ORDER_NUMBER_PAYLOAD_KEY])) {
  28.                 continue;
  29.             }
  30.             $payload['productNumber'] = $payload[OrderNumberCartProcessor::B2B_ORDER_NUMBER_PAYLOAD_KEY];
  31.             $lineItem->setPayload($payload);
  32.         }
  33.     }
  34. }