custom/plugins/PremsAutoComplete6/src/Storefront/Page/Checkout/Subscriber/PageSubscriber.php line 54

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * PremSoft
  4.  * Copyright © 2019 Premsoft - Sven Mittreiter
  5.  *
  6.  * @copyright  Copyright (c) 2019, premsoft - Sven Mittreiter (http://www.premsoft.de)
  7.  * @author     Sven Mittreiter <info@premsoft.de>
  8.  */
  9. namespace Prems\Plugin\PremsAutoComplete6\Storefront\Page\Checkout\Subscriber;
  10. use Prems\Plugin\PremsAutoComplete6\Core\AutoComplete\Storefront\ConfigService;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  12. use Shopware\Storefront\Page\Account\CustomerGroupRegistration\CustomerGroupRegistrationPageLoadedEvent;
  13. use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
  14. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  15. use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoadedEvent;
  16. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  17. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  18. use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. class PageSubscriber implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @var ConfigService
  24.      */
  25.     private $configService;
  26.     public function __construct(
  27.         ConfigService $configService
  28.     ) {
  29.         $this->configService $configService;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             CheckoutConfirmPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
  35.             CheckoutRegisterPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
  36.             AccountOverviewPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
  37.             AccountLoginPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
  38.             AddressDetailPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
  39.             CustomerGroupRegistrationPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
  40.             AccountEditOrderPageLoadedEvent::class => 'addAutoCompleteSettingsToPage'
  41.         ];
  42.     }
  43.     /**
  44.      * @param CheckoutRegisterPageLoadedEvent $event
  45.      *
  46.      * @throws InconsistentCriteriaIdsException
  47.      */
  48.     public function addAutoCompleteSettingsToPage($event): void
  49.     {
  50.         /** \Shopware\Core\Framework\Struct\Struct */
  51.         $autocompleteSettings null;
  52.         if ($event instanceof CheckoutConfirmPageLoadedEvent
  53.             || $event instanceof CheckoutRegisterPageLoadedEvent
  54.             || $event instanceof AccountLoginPageLoadedEvent
  55.             || $event instanceof AddressDetailPageLoadedEvent
  56.             || $event instanceof AccountOverviewPageLoadedEvent
  57.             || $event instanceof CustomerGroupRegistrationPageLoadedEvent
  58.             || $event instanceof AccountEditOrderPageLoadedEvent) {
  59.             $autocompleteSettings $this->configService->getConfig();
  60.         }
  61.         if (!$autocompleteSettings) {
  62.             return;
  63.         }
  64.         $event->getPage()->addExtension('premsAutoComplete'$autocompleteSettings);
  65.     }
  66. }