custom/plugins/TwigelSportLabel/src/Subscriber/CustomerSubscriber.php line 73

Open in your IDE?
  1. <?php
  2. namespace Twigel\SportLabel\Subscriber;
  3. use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository;
  7. use Shopware\Core\System\SystemConfig\SystemConfigService;
  8. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. class CustomerSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var EntityRepositoryInterface
  15.      */
  16.     private EntityRepositoryInterface $customerRepository;
  17.     /**
  18.      * @var SystemConfigService
  19.      */
  20.     private SystemConfigService $config;
  21.     /**
  22.      * @var EntityRepositoryInterface
  23.      */
  24.     private EntityRepositoryInterface $groupRepository;
  25.     /**
  26.      * @var RequestStack
  27.      */
  28.     private RequestStack $request;
  29.     public function __construct(
  30.         EntityRepositoryInterface $customerRepository,
  31.         SystemConfigService       $config,
  32.         EntityRepositoryInterface $groupRepository,
  33.         RequestStack              $request
  34.     )
  35.     {
  36.         $this->customerRepository $customerRepository;
  37.         $this->config $config;
  38.         $this->groupRepository $groupRepository;
  39.         $this->request $request;
  40.     }
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             CustomerRegisterEvent::class => 'customerRegistry',
  45.             GenericPageLoadedEvent::class => 'onPageLoaded'
  46.         ];
  47.     }
  48.     public function customerRegistry(CustomerRegisterEvent $event)
  49.     {
  50. //        if ($this->request->getCurrentRequest()->get('accountType') !== 'client' && $this->request->getCurrentRequest()->get('accountType') !== '') {
  51. //            $pluginConfig = $this->config->get('TwigelSportLabel')['config'];
  52. //            if (array_key_exists('businessGroup', $pluginConfig) && !is_null($pluginConfig['businessGroup'])) {
  53. //                $businessGroupId = $pluginConfig['businessGroup'];
  54. //                $event->getCustomer()->setGroupId($businessGroupId);
  55. //                $this->customerRepository->update([
  56. //                    [
  57. //                        'id' => $event->getCustomer()->getId(),
  58. //                        'groupId' => $businessGroupId
  59. //                    ]
  60. //                ], $event->getContext());
  61. //            }
  62. //        }
  63.     }
  64.     public function onPageLoaded(GenericPageLoadedEvent $event){
  65.         $pluginConfig $this->config->get('TwigelSportLabel')['config'];
  66.         if (array_key_exists('businessGroup'$pluginConfig)){
  67.             $businessGroupId $pluginConfig['businessGroup'];
  68.             $groups $this->groupRepository->search(new Criteria([$businessGroupId]), $event->getContext())->getElements();
  69.             if ($groups){
  70.                 foreach ($groups as $group){
  71.                     if ($group->getregistrationTitle()){
  72.                         $url $this->request->getCurrentRequest()->get('sw-storefront-url') .'/'$group->getregistrationTitle();
  73.                         $event->getPage()->assign(['bussinessUrl' => $url]);
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }