custom/static-plugins/K3nMerchant/src/Subscriber/Checkout/CheckoutConfirmPageLoaded.php line 45

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace K3n\Merchant\Subscriber\Checkout;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  8. use Shopware\Core\System\User\UserCollection;
  9. use Shopware\Core\System\User\UserEntity;
  10. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class CheckoutConfirmPageLoaded implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var EntityRepositoryInterface
  16.      */
  17.     private $userRepository;
  18.     /**
  19.      * @param EntityRepositoryInterface $userRepository
  20.      */
  21.     public function __construct(EntityRepositoryInterface $userRepository)
  22.     {
  23.         $this->userRepository $userRepository;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoaded'
  32.         ];
  33.     }
  34.     /**
  35.      * @param CheckoutConfirmPageLoadedEvent $event
  36.      * @return void
  37.      */
  38.     public function onCheckoutConfirmPageLoaded(CheckoutConfirmPageLoadedEvent $event): void
  39.     {
  40.         $page $event->getPage();
  41.         $page->assign([
  42.             'merchantArray' => $this->getUsersByRole('Händler'$event),
  43.             'retailerArray' => $this->getUsersByRole('Retailer'$event),
  44.         ]);
  45.     }
  46.     public function getUsersByRole(string $roleNameCheckoutConfirmPageLoadedEvent $event): array
  47.     {
  48.         $criteria = new Criteria();
  49.         $criteria->addAssociation('aclRoles');
  50.         $criteria->addFilter(
  51.             new MultiFilter(
  52.                 MultiFilter::CONNECTION_OR,
  53.                 [
  54.                     new EqualsFilter('aclRoles.name'$roleName),
  55.                 ]
  56.             )
  57.         );
  58.         /** @var UserCollection $merchants */
  59.         $users $this->userRepository->search($criteria$event->getContext())->getElements();
  60.         $userArray = array();
  61.         /** @var UserEntity $merchant */
  62.         foreach ($users as $user) {
  63.             $userArray[$user->getId()] = $user->getFirstName().', '.$user->getLastName().', '.$user->getEmail();
  64.         }
  65.         return $userArray;
  66.     }
  67. }