<?php
namespace EnetQrCode\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use EnetQrCode\Extension\Checkout\Order\OrderQrCodeExtension;
use EnetQrCode\Struct\OrderQrCodeStruct;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Order\OrderEvents;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
class ExtensionSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
OrderEvents::ORDER_LOADED_EVENT => 'onOrderLoaded'
];
}
public function onOrderLoaded(EntityLoadedEvent $event): void
{
/** @var OrderEntity $orderEntity */
foreach($event->getEntities() as $orderEntity) {
$qrCodeStruct = new OrderQrCodeStruct();
$qrCodeStruct->setOrderNumber($orderEntity->getOrderNumber());
$qrCodeStruct->create();
$orderEntity->addExtension('enet_qrcode', $qrCodeStruct);
}
// dump($orderEntity);
// die();
}
}