From a1eaa4b1d50713f1235b74aca1e210d57aef9c69 Mon Sep 17 00:00:00 2001 From: arti0090 Date: Mon, 12 Apr 2021 10:19:35 +0200 Subject: [PATCH] move cartBlamerListener to proper bundle --- .../EventListener/CartBlamerListener.php | 107 ------------------ .../EventListener/CartBlamerListener.php | 0 .../EventListener/CartBlamerListenerSpec.php | 0 3 files changed, 107 deletions(-) delete mode 100644 src/Sylius/Bundle/CoreBundle/EventListener/CartBlamerListener.php create mode 100644 src/Sylius/Bundle/ShopBundle/EventListener/CartBlamerListener.php rename src/Sylius/Bundle/{CoreBundle => ShopBundle}/spec/EventListener/CartBlamerListenerSpec.php (100%) diff --git a/src/Sylius/Bundle/CoreBundle/EventListener/CartBlamerListener.php b/src/Sylius/Bundle/CoreBundle/EventListener/CartBlamerListener.php deleted file mode 100644 index e8ff60d3a30a..000000000000 --- a/src/Sylius/Bundle/CoreBundle/EventListener/CartBlamerListener.php +++ /dev/null @@ -1,107 +0,0 @@ -cartManager = $cartManager; - $this->cartContext = $cartContext; - $this->uriBasedSectionContext = $uriBasedSectionContext; - } - - public function onImplicitLogin(UserEvent $userEvent): void - { - if (!$this->uriBasedSectionContext->getSection() instanceof ShopSection) { - return; - } - - $user = $userEvent->getUser(); - if (!$user instanceof ShopUserInterface) { - return; - } - - $this->blame($user); - } - - public function onInteractiveLogin(InteractiveLoginEvent $interactiveLoginEvent): void - { - $section = $this->uriBasedSectionContext->getSection(); - if (!$section instanceof ShopSection && !$section instanceof ShopApiSection) { - return; - } - - $user = $interactiveLoginEvent->getAuthenticationToken()->getUser(); - if (!$user instanceof ShopUserInterface) { - return; - } - - $this->blame($user); - } - - private function blame(ShopUserInterface $user): void - { - $cart = $this->getCart(); - if (null === $cart) { - return; - } - - $cart->setCustomer($user->getCustomer()); - $this->cartManager->persist($cart); - $this->cartManager->flush(); - } - - /** - * @throws UnexpectedTypeException - */ - private function getCart(): ?OrderInterface - { - try { - $cart = $this->cartContext->getCart(); - } catch (CartNotFoundException $exception) { - return null; - } - - if (!$cart instanceof OrderInterface) { - throw new UnexpectedTypeException($cart, OrderInterface::class); - } - - return $cart; - } -} diff --git a/src/Sylius/Bundle/ShopBundle/EventListener/CartBlamerListener.php b/src/Sylius/Bundle/ShopBundle/EventListener/CartBlamerListener.php new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/src/Sylius/Bundle/CoreBundle/spec/EventListener/CartBlamerListenerSpec.php b/src/Sylius/Bundle/ShopBundle/spec/EventListener/CartBlamerListenerSpec.php similarity index 100% rename from src/Sylius/Bundle/CoreBundle/spec/EventListener/CartBlamerListenerSpec.php rename to src/Sylius/Bundle/ShopBundle/spec/EventListener/CartBlamerListenerSpec.php