custom/plugins/EnetQrCode/src/Subscriber/ExtensionSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. namespace EnetQrCode\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use EnetQrCode\Extension\Checkout\Order\OrderQrCodeExtension;
  5. use EnetQrCode\Struct\OrderQrCodeStruct;
  6. use Shopware\Core\Checkout\Order\OrderEntity;
  7. use Shopware\Core\Checkout\Order\OrderEvents;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  9. class ExtensionSubscriber implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents()
  12.     {
  13.         return [
  14.             OrderEvents::ORDER_LOADED_EVENT => 'onOrderLoaded'
  15.         ];
  16.     }
  17.     public function onOrderLoaded(EntityLoadedEvent $event): void
  18.     {
  19.         /** @var OrderEntity $orderEntity */
  20.         foreach($event->getEntities() as $orderEntity) {
  21.             $qrCodeStruct = new OrderQrCodeStruct();
  22.             $qrCodeStruct->setOrderNumber($orderEntity->getOrderNumber());
  23.             $qrCodeStruct->create();
  24.             $orderEntity->addExtension('enet_qrcode'$qrCodeStruct);
  25.         }
  26. //        dump($orderEntity);
  27. //        die();
  28.     }
  29. }