function it_removes_a_cart_which_has_been_updated_before_configured_date(OrderRepositoryInterface $orderRepository, OrderInterface $firstCart, OrderInterface $secondCart) { $orderRepository->findCartsNotModifiedSince(Argument::type('\\DateTime'))->willReturn([$firstCart, $secondCart]); $orderRepository->remove($firstCart)->shouldBeCalled(); $orderRepository->remove($secondCart)->shouldBeCalled(); $this->remove(); }
public function remove() { $expiredCarts = $this->orderRepository->findCartsNotModifiedSince(new \DateTime('-' . $this->expirationPeriod)); foreach ($expiredCarts as $expiredCart) { $this->orderRepository->remove($expiredCart); } }
function it_throws_cart_not_found_exception_and_removes_id_from_session_when_cart_is_not_found(SessionInterface $session, OrderRepositoryInterface $orderRepository) { $session->has('session_key_name')->willReturn(true); $session->get('session_key_name')->willReturn(12345); $orderRepository->findCartById(12345)->willReturn(null); $session->remove('session_key_name')->shouldBeCalled(); $this->shouldThrow(CartNotFoundException::class)->during('getCart'); }
function it_cancels_unpaid_orders(Factory $stateMachineFactory, OrderInterface $firstOrder, OrderInterface $secondOrder, OrderRepositoryInterface $orderRepository, StateMachineInterface $firstOrderStateMachine, StateMachineInterface $secondOrderStateMachine) { $orderRepository->findOrdersUnpaidSince(Argument::type(\DateTime::class))->willReturn([$firstOrder, $secondOrder]); $stateMachineFactory->get($firstOrder, 'sylius_order')->willReturn($firstOrderStateMachine); $stateMachineFactory->get($secondOrder, 'sylius_order')->willReturn($secondOrderStateMachine); $firstOrderStateMachine->apply(OrderTransitions::TRANSITION_CANCEL)->shouldBeCalled(); $secondOrderStateMachine->apply(OrderTransitions::TRANSITION_CANCEL)->shouldBeCalled(); $this->cancel(); }
/** * {@inheritdoc} */ public function getCart() { if (!$this->session->has($this->sessionKeyName)) { throw new CartNotFoundException('Sylius was not able to find the cart in session'); } $cart = $this->orderRepository->findCartById($this->session->get($this->sessionKeyName)); if (null === $cart) { $this->session->remove($this->sessionKeyName); throw new CartNotFoundException('Sylius was not able to find the cart in session'); } return $cart; }
/** * @param Request $request * @param mixed $tokenValue * * @return Response */ public function prepareCaptureAction(Request $request, $tokenValue) { $configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request); $order = $this->orderRepository->findOneByTokenValue($tokenValue); if (null === $order) { throw new NotFoundHttpException(sprintf('Order with token "%s" does not exist.', $tokenValue)); } $request->getSession()->set('sylius_order_id', $order->getId()); $options = $configuration->getParameters()->get('redirect'); $payment = $order->getLastNewPayment(); if (null === $payment) { throw new NotFoundHttpException(sprintf('Order with token "%s" has no pending payments.', $tokenValue)); } $captureToken = $this->getTokenFactory()->createCaptureToken($payment->getMethod()->getGateway(), $payment, isset($options['route']) ? $options['route'] : null, isset($options['parameters']) ? $options['parameters'] : []); $view = View::createRedirect($captureToken->getTargetUrl()); return $this->viewHandler->handle($configuration, $view); }
/** * @return OrderInterface * * @throws \RuntimeException */ private function getLastOrder() { $customer = $this->sharedStorage->get('user')->getCustomer(); $orders = $this->orderRepository->findByCustomer($customer); $lastOrder = end($orders); if (false === $lastOrder) { throw new \RuntimeException(sprintf('There is no last order for %s', $customer->getFullName())); } return $lastOrder; }
/** * {@inheritdoc} */ public function getStatistics() { return new DashboardStatistics($this->orderRepository->getTotalSales(), $this->orderRepository->count(), $this->customerRepository->count()); }