function it_throws_handle_exception_if_cart_was_not_found(CartContextInterface $cartContext, ObjectManager $cartManager) { $cartContext->getCart()->willThrow(CartNotFoundException::class); $cartManager->persist(Argument::any())->shouldNotBeCalled(); $cartManager->flush()->shouldNotBeCalled(); $this->shouldThrow(HandleException::class)->during('handle', ['en_GB']); }
function its_cart_contexts_can_have_priority(CartContextInterface $firstCartContext, CartContextInterface $secondCartContext, OrderInterface $cart) { $firstCartContext->getCart()->shouldNotBeCalled(); $secondCartContext->getCart()->willReturn($cart); $this->addContext($firstCartContext, -1); $this->addContext($secondCartContext, 0); $this->getCart()->shouldReturn($cart); }
function it_throws_a_cart_not_found_exception_if_locale_code_is_undefined(CartContextInterface $cartContext, ShopperContextInterface $shopperContext, ChannelInterface $channel, OrderInterface $cart) { $cartContext->getCart()->willReturn($cart); $shopperContext->getChannel()->willReturn($channel); $shopperContext->getCurrencyCode()->willReturn('PLN'); $shopperContext->getLocaleCode()->willThrow(LocaleNotFoundException::class); $this->shouldThrow(CartNotFoundException::class)->during('getCart'); }
function it_handles_cart_currency_code_change(CartContextInterface $cartContext, OrderUpdaterInterface $orderUpdater, EventDispatcherInterface $eventDispatcher, EntityManagerInterface $orderManager, OrderInterface $cart) { $cartContext->getCart()->willReturn($cart); $cart->setCurrencyCode('USD')->shouldBeCalled(); $orderUpdater->update($cart)->shouldBeCalled(); $orderManager->persist($cart)->shouldBeCalled(); $orderManager->flush()->shouldBeCalled(); $eventDispatcher->dispatch(SyliusCartEvents::CART_CHANGE, Argument::type(GenericEvent::class))->shouldBeCalled(); $this->handle('USD'); }
/** * @param Event $event * * @throws UnexpectedTypeException */ public function recalculateCartWhileLogin(Event $event) { try { $cart = $this->cartContext->getCart(); } catch (CartNotFoundException $exception) { return; } if (!$cart instanceof OrderInterface) { throw new UnexpectedTypeException($cart, OrderInterface::class); } $this->orderProcessor->process($cart); }
/** * {@inheritdoc} */ public function handle($code) { try { /** @var OrderInterface $cart */ $cart = $this->cartContext->getCart(); $cart->setLocaleCode($code); $this->cartManager->persist($cart); $this->cartManager->flush(); } catch (CartNotFoundException $exception) { throw new HandleException(self::class, 'Sylius was unable to find the cart.', $exception); } }
/** * @return OrderInterface * * @throws UnexpectedTypeException */ private function getCart() { try { $cart = $this->cartContext->getCart(); } catch (CartNotFoundException $exception) { return null; } if (!$cart instanceof OrderInterface) { throw new UnexpectedTypeException($cart, OrderInterface::class); } return $cart; }
/** * {@inheritdoc} */ public function handle($code) { try { /** @var OrderInterface $cart */ $cart = $this->cartContext->getCart(); $cart->setCurrencyCode($code); $this->exchangeRateUpdater->update($cart); $this->orderManager->persist($cart); $this->orderManager->flush(); $this->eventDispatcher->dispatch(SyliusCartEvents::CART_CHANGE, new CartEvent($cart)); } catch (CartNotFoundException $exception) { throw new HandleException(self::class, 'Sylius was unable to find the cart.', $exception); } }
/** * @param FilterResponseEvent $event */ public function onKernelResponse(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } /** @var Request $request */ $request = $event->getRequest(); try { $cart = $this->cartContext->getCart(); } catch (CartNotFoundException $exception) { return; } if (null !== $cart && null !== $cart->getId() && null !== $cart->getChannel()) { $session = $request->getSession(); $session->set(sprintf('%s.%s', $this->sessionKeyName, $cart->getChannel()->getCode()), $cart->getId()); } }
/** * {@inheritdoc} */ public function getCart() { if (null !== $this->cart) { return $this->cart; } /** @var OrderInterface $cart */ $cart = $this->cartContext->getCart(); try { $cart->setChannel($this->shopperContext->getChannel()); $cart->setCurrencyCode($this->shopperContext->getCurrencyCode()); $cart->setLocaleCode($this->shopperContext->getLocaleCode()); } catch (ChannelNotFoundException $exception) { throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception); } catch (CurrencyNotFoundException $exception) { throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception); } catch (LocaleNotFoundException $exception) { throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception); } $cart->setCustomer($this->shopperContext->getCustomer()); $this->cart = $cart; return $cart; }
/** * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); if (!$this->requestMatcher->matches($request)) { return; } /** @var OrderInterface $order */ $order = $this->cartContext->getCart(); if ($order->isEmpty()) { $event->setResponse(new RedirectResponse($this->urlGenerator->generate('sylius_shop_cart_summary'))); } $stateMachine = $this->stateMachineFactory->get($order, OrderCheckoutTransitions::GRAPH); if ($stateMachine->can($this->getRequestedTransition($request))) { return; } if (null !== ($referer = $this->getReferer($request))) { $event->setResponse(new RedirectResponse($referer)); return; } $event->setResponse(new RedirectResponse($this->urlGenerator->generateForOrderCheckoutState($order))); }
/** * @return OrderInterface|null */ public function getCurrentCart() { return $this->cartContext->getCart(); }
function it_does_nothing_if_cannot_find_cart(CartContextInterface $cartContext, OrderProcessorInterface $orderProcessor, Event $event) { $cartContext->getCart()->willThrow(CartNotFoundException::class); $orderProcessor->process(Argument::any())->shouldNotBeCalled(); $this->recalculateCartWhileLogin($event); }
function it_does_nothing_if_there_is_no_existing_cart_on_interactive_login(CartContextInterface $cartContext, InteractiveLoginEvent $interactiveLoginEvent, TokenInterface $token, ShopUserInterface $user) { $cartContext->getCart()->willThrow(CartNotFoundException::class); $interactiveLoginEvent->getAuthenticationToken()->willReturn($token); $token->getUser()->willReturn($user); $this->onInteractiveLogin($interactiveLoginEvent); }
function it_returns_current_cart_via_provider(CartContextInterface $cartContext, OrderInterface $cart) { $cartContext->getCart()->willReturn($cart); $this->getCurrentCart()->shouldReturn($cart); }