<?php declare(strict_types=1);
namespace Ecd\econdWebAnalytics\Storefront\Page\Account\Overview\Subscriber;
use ErrorException;
use Shopware\Core\Framework\Struct\ArrayEntity;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
class AccountOverviewPageLoadedEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
AccountOverviewPageLoadedEvent::class => 'onAccountOverviewPageLoadedEvent'
];
}
public function onAccountOverviewPageLoadedEvent(AccountOverviewPageLoadedEvent $event)
{
$page = $event->getPage();
$ana = [
'content' => strtok($_SERVER["REQUEST_URI"], '?'),
'pageId' => md5(strtok($_SERVER["REQUEST_URI"], '?'))
];
try {
if ($_SESSION['emos_LogInRequestSend'] === true) {
$ana['login_userid'] = $event->getSalesChannelContext()->getCustomer()->getCustomerNumber();
unset($_SESSION['emos_LogInRequestSend']);
}
} catch (ErrorException $e) {
unset($ana['login_userid']);
}
try {
if ($_SESSION['emos_RegisterRequestSend'] === true) {
$ana['register_userid'] = $event->getSalesChannelContext()->getCustomer()->getCustomerNumber();
unset($_SESSION['emos_RegisterRequestSend']);
}
} catch (ErrorException $e) {
unset($ana['register_userid']);
}
$page->addExtension('ANA', new ArrayEntity($ana));
}
}