custom/plugins/FourtwosixWirthsExtension/src/Subscriber/EnrichOrderPayload.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace FourtwosixWirthsExtension\Subscriber;
  3. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class EnrichOrderPayload implements EventSubscriberInterface
  7. {
  8.     private $lineItemRepository;
  9.     public function __construct(
  10.         EntityRepository $lineItemRepository
  11.     )
  12.     {
  13.         $this->lineItemRepository $lineItemRepository;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             CheckoutOrderPlacedEvent::class => 'onOrderPlaced',
  19.         ];
  20.     }
  21.     public function onOrderPlaced(CheckoutOrderPlacedEvent $event): void
  22.     {
  23.         $context $event->getContext();
  24.         foreach ($event->getOrder()->getLineItems() as $item) {
  25.             if (!is_null($item->getParentId())) {
  26.                 if ($item->getProductId()) {
  27.                     $this->lineItemRepository->upsert([['id' => $item->getId(), 'identifier'=> $item->getProductId()]], $context);
  28.                 }
  29.             }
  30.         }
  31.     }
  32. }