vendor/ibexa/storefront/src/bundle/EventSubscriber/RegionResolverSubscriber.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\RegionResolveEvent;
  9. use Ibexa\Contracts\Storefront\Repository\RegionServiceInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. final class RegionResolverSubscriber implements EventSubscriberInterface
  12. {
  13. private RegionServiceInterface $regionService;
  14. public function __construct(RegionServiceInterface $regionService)
  15. {
  16. $this->regionService = $regionService;
  17. }
  18. public static function getSubscribedEvents(): array
  19. {
  20. return [
  21. RegionResolveEvent::class => ['onRegionResolve', -90],
  22. ];
  23. }
  24. public function onRegionResolve(RegionResolveEvent $event): void
  25. {
  26. if ($event->getRegion() !== null) {
  27. return;
  28. }
  29. $region = $this->regionService->getSessionRegion();
  30. if ($region !== null) {
  31. $event->setRegion($region);
  32. $event->stopPropagation();
  33. }
  34. }
  35. }