<?php declare(strict_types=1);
namespace NetzpQuickBuy6\Subscriber;
use NetzpQuickBuy6\Components\QuickBuyHelper;
use Shopware\Core\Framework\Struct\ArrayEntity;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FrontendSubscriber implements EventSubscriberInterface
{
const SEARCH_TYPE_BLOG = 10;
private $container;
private $config;
private $helper;
public function __construct(
ContainerInterface $container,
SystemConfigService $config,
QuickBuyHelper $helper)
{
$this->container = $container;
$this->config = $config;
$this->helper = $helper;
}
public static function getSubscribedEvents(): array
{
return [
AccountOrderPageLoadedEvent::class => 'loadAccountOrderPage'
];
}
public function loadAccountOrderPage(AccountOrderPageLoadedEvent $event): void
{
$page = $event->getPage();
$orders = $page->getOrders();
if($orders == null) {
return;
}
foreach ($orders as $order) {
$orderId = $order->getId();
$documents = $this->helper->getDocumentsForOrder($orderId, $event->getSalesChannelContext());
$order->addExtension('netzpQuickBuyDocuments', new ArrayEntity(['documents' => $documents]));
}
}
}