custom/plugins/AcrisMerchantRegisterCS/src/Storefront/Subscriber/ReplaceRegisterFormSubscriber.php line 37

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\MerchantRegister\Storefront\Subscriber;
  3. use Acris\MerchantRegister\Components\CustomerGroupService;
  4. use Acris\MerchantRegister\Components\Struct\CustomerGroupActivatedStruct;
  5. use Acris\Search\Storefront\Page\Manufacturer\ManufacturerPage;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. use Shopware\Storefront\Page\Account\Login\AccountLoginPage;
  8. use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
  9. use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
  10. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  11. use Shopware\Storefront\Page\Page;
  12. use Shopware\Storefront\Page\PageLoadedEvent;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Shopware\Core\Framework\Struct\Struct;
  15. class ReplaceRegisterFormSubscriber implements EventSubscriberInterface
  16. {
  17.     private CustomerGroupService $customerGroupService;
  18.     private SystemConfigService $systemConfigService;
  19.     public function __construct(CustomerGroupService $customerGroupServiceSystemConfigService $systemConfigService)
  20.     {
  21.         $this->customerGroupService $customerGroupService;
  22.         $this->systemConfigService $systemConfigService;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             AccountLoginPageLoadedEvent::class => 'onAccountLoginPageLoaded',
  28.             CheckoutRegisterPageLoadedEvent::class => 'onCheckoutRegisterPageLoaded'
  29.         ];
  30.     }
  31.     public function onAccountLoginPageLoaded(AccountLoginPageLoadedEvent $event):void
  32.     {
  33.         $this->addPageExtensions($event);
  34.     }
  35.     public function onCheckoutRegisterPageLoaded(CheckoutRegisterPageLoadedEvent $event):void
  36.     {
  37.         $this->addPageExtensions($event);
  38.     }
  39.     private function addPageExtensions(PageLoadedEvent $event): void {
  40.         $page $event->getPage();
  41.         $context $event->getContext();
  42.         $configCustomerGroupFormId $this->systemConfigService->get('AcrisMerchantRegisterCS.config.replaceRegisterFormWith'$event->getSalesChannelContext()->getSalesChannelId());
  43.         if (!empty($configCustomerGroupFormId)) {
  44.             $customerGroup$this->customerGroupService->getCustomerGroupById($context$configCustomerGroupFormId);
  45.             if (!empty($customerGroup) && $customerGroup->registrationActive) {
  46.                 $page->addExtension(CustomerGroupActivatedStruct::CUSTOMER_GROUP_ACTIVATED_EXTENSION, new CustomerGroupActivatedStruct());
  47.                 $this->maintainCustomerGroupProperty($page$customerGroup);
  48.             }
  49.         }
  50.     }
  51.     private function maintainCustomerGroupProperty(Page $pageStruct $customerGroupEntity) {
  52.         $page->addExtension('configCustomerGroup'$customerGroupEntity);
  53.         $page->group $customerGroupEntity;
  54.     }
  55. }