custom/plugins/RpayPayments/src/Components/AdminOrders/Subscriber/ProfileConfigSubscriber.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (c) Ratepay GmbH
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace Ratepay\RpayPayments\Components\AdminOrders\Subscriber;
  10. use Ratepay\RpayPayments\Components\ProfileConfig\Event\CreateProfileConfigCriteriaEvent;
  11. use Ratepay\RpayPayments\Components\ProfileConfig\Model\ProfileConfigEntity;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. class ProfileConfigSubscriber implements EventSubscriberInterface
  16. {
  17.     private RequestStack $requestStack;
  18.     private string $sessionKey;
  19.     public function __construct(RequestStack $requestStackstring $sessionKey)
  20.     {
  21.         $this->requestStack $requestStack;
  22.         $this->sessionKey $sessionKey;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             CreateProfileConfigCriteriaEvent::class => 'onLoadConfig',
  28.         ];
  29.     }
  30.     public function onLoadConfig(CreateProfileConfigCriteriaEvent $event): void
  31.     {
  32.         $session $this->requestStack->getMainRequest()->getSession();
  33.         if ($session->get($this->sessionKey) === true) {
  34.             $event->getCriteria()->addFilter(new EqualsFilter(ProfileConfigEntity::FIELD_ONLY_ADMIN_ORDERStrue));
  35.         } else {
  36.             $event->getCriteria()->addFilter(new EqualsFilter(ProfileConfigEntity::FIELD_ONLY_ADMIN_ORDERSfalse));
  37.         }
  38.     }
  39. }