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

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