<?php declare(strict_types=1);
namespace Ecd\econdWebAnalytics\Storefront\Page\Checkout\Confirm\Subscriber;
use ErrorException;
use Shopware\Core\Framework\Struct\ArrayEntity;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CheckoutConfirmPageLoadedEventSubscriber implements EventSubscriberInterface
{
private $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoadedEvent'
];
}
public function onCheckoutConfirmPageLoadedEvent(CheckoutConfirmPageLoadedEvent $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'] = md5($event->getSalesChannelContext()->getCustomer()->getEmail());
unset($_SESSION['emos_LogInRequestSend']);
}
} catch (ErrorException $e) {
unset($ana['login_userid']);
}
try {
if ($_SESSION['emos_RegisterRequestSend'] === true) {
$ana['register_userid'] = md5($event->getSalesChannelContext()->getCustomer()->getEmail());
unset($_SESSION['emos_RegisterRequestSend']);
}
} catch (ErrorException $e) {
unset($ana['register_userid']);
}
$page->addExtension('ANA', new ArrayEntity($ana));
}
}