<?php
namespace MojeBambino\Popup\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use MojeBambino\Popup\Struct\Baner;
use MojeBambino\Popup\Entity\PopupEntity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
class FooterPageletSubscriber implements EventSubscriberInterface
{
protected EntityRepositoryInterface $popupRepository;
public function __construct(EntityRepositoryInterface $popupRepository){
$this->popupRepository = $popupRepository;
}
public static function getSubscribedEvents(): array
{
return [
FooterPageletLoadedEvent::class => 'addFooterBaner',
];
}
public function addFooterBaner(FooterPageletLoadedEvent $event): void
{
$baner = new Baner();
$criteria = new Criteria();
$dupa = $this->popupRepository->search($criteria, $event->getContext());
$baner->setBaner($dupa->getElements()); //zwraca tablicę obiektów, czyli w tym przypadku w tablicy jest jeden obiekt z obrazkiem
$event->getPagelet()->addExtension('footer_baner', $baner);
}
}