custom/plugins/OttSaleCategory/src/Subscriber/NavigationPageSubscriber.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Ott\SaleCategory\Subscriber;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  4. use Shopware\Core\Framework\Struct\ArrayStruct;
  5. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  6. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class NavigationPageSubscriber implements EventSubscriberInterface
  9. {
  10.     private SalesChannelRepositoryInterface $salutationRepository;
  11.     public function __construct(
  12.         SalesChannelRepositoryInterface $salutationRepository
  13.     )
  14.     {
  15.         $this->salutationRepository $salutationRepository;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             NavigationPageLoadedEvent::class => 'onNavigationPageLoadedEvent',
  21.         ];
  22.     }
  23.     public function onNavigationPageLoadedEvent(NavigationPageLoadedEvent $event): void
  24.     {
  25.         $salutationIds = [];
  26.         $salutationCollection $this->salutationRepository->search(
  27.             new Criteria(),
  28.             $event->getSalesChannelContext()
  29.         )->getEntities();
  30.         foreach ($salutationCollection as $salutation) {
  31.             $salutationIds[$salutation->getSalutationKey()] = $salutation->getId();
  32.         }
  33.         $event->getPage()->addExtension('ottSalesChannelSalutations', new ArrayStruct(['data' => $salutationIds]));
  34.     }
  35. }