src/Sylius/Bundle/ShopBundle/EventListener/OrderLocaleAssigner.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ShopBundle\EventListener;
  12. use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
  13. use Sylius\Component\Core\Model\OrderInterface;
  14. use Sylius\Component\Locale\Context\LocaleContextInterface;
  15. use Webmozart\Assert\Assert;
  16. final class OrderLocaleAssigner
  17. {
  18.     /** @var LocaleContextInterface */
  19.     private $localeContext;
  20.     public function __construct(LocaleContextInterface $localeContext)
  21.     {
  22.         $this->localeContext $localeContext;
  23.     }
  24.     public function assignLocale(ResourceControllerEvent $event): void
  25.     {
  26.         /** @var OrderInterface $order */
  27.         $order $event->getSubject();
  28.         Assert::isInstanceOf($orderOrderInterface::class);
  29.         $order->setLocaleCode($this->localeContext->getLocaleCode());
  30.     }
  31. }