custom/plugins/SmsBecoTechnicTheme/src/Subscriber/FooterPageletSubscriber.php line 71

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace SmsBecoTechnicTheme\Subscriber;
  3. use Shopware\Core\Content\Category\CategoryEntity;
  4. use Shopware\Core\Content\Category\Service\NavigationLoader;
  5. use Shopware\Core\Content\Category\Service\NavigationLoaderInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  7. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  10. use Shopware\Core\PlatformRequest;
  11. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService;
  12. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceInterface;
  13. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceParameters;
  14. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  15. use Shopware\Core\System\SystemConfig\SystemConfigService;
  16. use Shopware\Storefront\Page\Navigation\NavigationPageLoader;
  17. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. class FooterPageletSubscriber implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var NavigationLoader
  23.      */
  24.     private $navigationLoader;
  25.     /**
  26.      * @var SystemConfigService
  27.      */
  28.     private $systemConfigService;
  29.     /**
  30.      * @var SalesChannelContextServiceInterface
  31.      */
  32.     private $salesChannelContext;
  33.     /**
  34.      * @var EntityRepositoryInterface
  35.      */
  36.     private $entityRepository;
  37.     /**
  38.      * @var EntityRepositoryInterface
  39.      */
  40.     private $customerGroupRepository;
  41.     public function __construct(
  42.         NavigationLoader                    $navigationLoader,
  43.         SystemConfigService                 $configService,
  44.         SalesChannelContextServiceInterface $salesChannelContext,
  45.         EntityRepositoryInterface           $entityRepository,
  46.         EntityRepositoryInterface           $customerGroupRepository
  47.     )
  48.     {
  49.         $this->navigationLoader $navigationLoader;
  50.         $this->systemConfigService $configService;
  51.         $this->salesChannelContext $salesChannelContext;
  52.         $this->entityRepository $entityRepository;
  53.         $this->customerGroupRepository $customerGroupRepository;
  54.     }
  55.     public static function getSubscribedEvents(): array
  56.     {
  57.         return [
  58.             FooterPageletLoadedEvent::class => 'addCustomNavigationAndCustomerGroup',
  59.         ];
  60.     }
  61.     public function addCustomNavigationAndCustomerGroup(FooterPageletLoadedEvent $event): void
  62.     {
  63.         $contextToken $event->getRequest()->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN);
  64.         $salesChannelId $event->getRequest()->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  65.         $salesChannelContextParameters = new SalesChannelContextServiceParameters($salesChannelId$contextToken$event->getRequest()->headers->get(PlatformRequest::HEADER_LANGUAGE_ID));
  66.         $context $this->salesChannelContext->get(
  67.             $salesChannelContextParameters
  68.         )->getContext();
  69.         $footerCategoryId $this->systemConfigService->get('SmsBecoTechnicTheme.config.footerCategory');
  70.         if (!is_null($footerCategoryId)) {
  71.             $criteria = new Criteria([$footerCategoryId]);
  72.             $criteria->addAssociation('children');
  73.             /** @var EntitySearchResult $category */
  74.             $result $this->entityRepository->search(
  75.                 $criteria,
  76.                 $context
  77.             );
  78.             $event->getPagelet()->addExtension('footerBottomCategory'$result->first());
  79.         }
  80.         //add current Customer Group
  81.         if ($event->getSalesChannelContext()->getCustomer()) {
  82.             $customerGroupId $event->getSalesChannelContext()->getCustomer()->getGroupId();
  83.             $customerGroup $this->customerGroupRepository->search((new Criteria([$customerGroupId])), $event->getContext());
  84.             $event->getSalesChannelContext()->getCustomer()->addExtension('currentCustomerGroup'$customerGroup->first());
  85.         }
  86.     }
  87. }