<?php declare(strict_types=1);
namespace Nd\Theme\Subscriber;
use Nd\Theme\Service\InstagramCommunicator;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddInstagramData implements EventSubscriberInterface
{
private InstagramCommunicator $instagramCommunicator;
public function __construct(InstagramCommunicator $instagramCommunicator){
$this->instagramCommunicator = $instagramCommunicator;
}
public static function getSubscribedEvents(): array
{
return [
FooterPageletLoadedEvent::class => 'addInstagramData'
];
}
public function addInstagramData(FooterPageletLoadedEvent $event): void
{
$instaMedia = $this->instagramCommunicator->getMediaByHashtag($event->getSalesChannelContext());
if(!$instaMedia){
return;
}
$data = new ArrayStruct();
$data->set("instagram", $instaMedia);
$event->getPagelet()->addExtension('instagram_posts', $data);
}
}