<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Bundle\Storefront\EventSubscriber;
use Ibexa\Contracts\ProductCatalog\Events\CurrencyResolveEvent;
use Ibexa\Contracts\Storefront\Repository\CurrencyServiceInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class CurrencyResolverSubscriber implements EventSubscriberInterface
{
private CurrencyServiceInterface $currencyService;
public function __construct(CurrencyServiceInterface $currencyService)
{
$this->currencyService = $currencyService;
}
public static function getSubscribedEvents(): array
{
return [
CurrencyResolveEvent::class => ['onCurrencyResolve', -90],
];
}
public function onCurrencyResolve(CurrencyResolveEvent $event): void
{
$currency = $this->currencyService->getSessionCurrency() ?? $this->currencyService->getDefaultCurrency();
if ($currency !== null) {
$event->setCurrency($currency);
// TODO: The following call shouldn't be need
$event->stopPropagation();
}
}
}