vendor/ibexa/storefront/src/bundle/EventSubscriber/CurrencyResolverSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\Storefront\EventSubscriber;
  8. use Ibexa\Contracts\ProductCatalog\Events\CurrencyResolveEvent;
  9. use Ibexa\Contracts\Storefront\Repository\CurrencyServiceInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. final class CurrencyResolverSubscriber implements EventSubscriberInterface
  12. {
  13. private CurrencyServiceInterface $currencyService;
  14. public function __construct(CurrencyServiceInterface $currencyService)
  15. {
  16. $this->currencyService = $currencyService;
  17. }
  18. public static function getSubscribedEvents(): array
  19. {
  20. return [
  21. CurrencyResolveEvent::class => ['onCurrencyResolve', -90],
  22. ];
  23. }
  24. public function onCurrencyResolve(CurrencyResolveEvent $event): void
  25. {
  26. $currency = $this->currencyService->getSessionCurrency() ?? $this->currencyService->getDefaultCurrency();
  27. if ($currency !== null) {
  28. $event->setCurrency($currency);
  29. // TODO: The following call shouldn't be need
  30. $event->stopPropagation();
  31. }
  32. }
  33. }