custom/plugins/System4ShopTheme/src/Subscriber/StorefrontSubscriber.php line 43

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace System4ShopTheme\Subscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Shopware\Storefront\Event\StorefrontRenderEvent;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\Context;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  12. class StorefrontSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var SystemConfigService
  16.      */
  17.     private $systemConfigService;
  18.     /**
  19.      * @var EntityRepositoryInterface
  20.      */
  21.     private $paymentIconsRepo;
  22.     public function __construct(
  23.         SystemConfigService $systemConfigService,
  24.         EntityRepositoryInterface $paymentIconsRepo
  25.     ) {
  26.         $this->systemConfigService $systemConfigService;
  27.         $this->paymentIconsRepo $paymentIconsRepo;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         // Return the events to listen to as array like this:  <event to listen to> => <method to execute>
  32.         return [
  33.             StorefrontRenderEvent::class => 'onStorefrontRender'
  34.         ];
  35.     }
  36.     public function onStorefrontRender(StorefrontRenderEvent $event)
  37.     {
  38.         $criteria = new Criteria();
  39.         $criteria->addAssociation('media');
  40.         $criteria->addFilter(new EqualsFilter('active'1));
  41.         $criteria->addSorting(new FieldSorting('position'FieldSorting::ASCENDING));
  42.         $paymentIcons $this->paymentIconsRepo->search($criteriaContext::createDefaultContext());
  43.         $event->setParameter('paymentIcons'$paymentIcons);
  44.     }
  45. }