<?php declare(strict_types=1);
/**
* PremSoft
* Copyright © 2019 Premsoft - Sven Mittreiter
*
* @copyright Copyright (c) 2019, premsoft - Sven Mittreiter (http://www.premsoft.de)
* @author Sven Mittreiter <info@premsoft.de>
*/
namespace Prems\Plugin\PremsAutoComplete6\Storefront\Page\Checkout\Subscriber;
use Prems\Plugin\PremsAutoComplete6\Core\AutoComplete\Storefront\ConfigService;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Storefront\Page\Account\CustomerGroupRegistration\CustomerGroupRegistrationPageLoadedEvent;
use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PageSubscriber implements EventSubscriberInterface
{
/**
* @var ConfigService
*/
private $configService;
public function __construct(
ConfigService $configService
) {
$this->configService = $configService;
}
public static function getSubscribedEvents(): array
{
return [
CheckoutConfirmPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
CheckoutRegisterPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
AccountOverviewPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
AccountLoginPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
AddressDetailPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
CustomerGroupRegistrationPageLoadedEvent::class => 'addAutoCompleteSettingsToPage',
AccountEditOrderPageLoadedEvent::class => 'addAutoCompleteSettingsToPage'
];
}
/**
* @param CheckoutRegisterPageLoadedEvent $event
*
* @throws InconsistentCriteriaIdsException
*/
public function addAutoCompleteSettingsToPage($event): void
{
/** \Shopware\Core\Framework\Struct\Struct */
$autocompleteSettings = null;
if ($event instanceof CheckoutConfirmPageLoadedEvent
|| $event instanceof CheckoutRegisterPageLoadedEvent
|| $event instanceof AccountLoginPageLoadedEvent
|| $event instanceof AddressDetailPageLoadedEvent
|| $event instanceof AccountOverviewPageLoadedEvent
|| $event instanceof CustomerGroupRegistrationPageLoadedEvent
|| $event instanceof AccountEditOrderPageLoadedEvent) {
$autocompleteSettings = $this->configService->getConfig();
}
if (!$autocompleteSettings) {
return;
}
$event->getPage()->addExtension('premsAutoComplete', $autocompleteSettings);
}
}