custom/plugins/OttOffcanvasNewsletter/src/Subscriber/FooterSubscriber.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace OttOffcanvasNewsletter\Subscriber;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  4. use Shopware\Core\Framework\Struct\ArrayEntity;
  5. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  6. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class FooterSubscriber implements EventSubscriberInterface
  9. {
  10.     private $salutationRepository;
  11.     public function __construct(SalesChannelRepositoryInterface $salutationRepository)
  12.     {
  13.         $this->salutationRepository $salutationRepository;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             FooterPageletLoadedEvent::class => 'onFooterPageletLoadedEvent',
  19.         ];
  20.     }
  21.     public function onFooterPageletLoadedEvent(FooterPageletLoadedEvent $event): void
  22.     {
  23.         $pagelet $event->getPagelet();
  24.         $salutationCollection $this->salutationRepository->search(new Criteria(), $event->getSalesChannelContext())->getEntities();
  25.         $salutationIds = [];
  26.         foreach ($salutationCollection as $salutation) {
  27.             $salutationKey $salutation->getSalutationKey();
  28.             $salutationId $salutation->getId();
  29.             if ('mr' === $salutationKey) {
  30.                 $salutationIds['mr'] = $salutationId;
  31.             } elseif ('mrs' === $salutationKey) {
  32.                 $salutationIds['mrs'] = $salutationId;
  33.             }
  34.         }
  35.         $pagelet->addExtension('ottSaleschannelNewsletterSalutations', new ArrayEntity($salutationIds));
  36.     }
  37. }