/** * @param GenericEvent $event * * @throws UnexpectedTypeException */ public function recalculateOrder(GenericEvent $event) { $order = $event->getSubject(); if (!$order instanceof OrderInterface) { throw new UnexpectedTypeException($order, OrderInterface::class); } $this->orderProcessor->process($order); }
/** * @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); }
/** * @Given /^the customer chose ("[^"]+" shipping method) with ("[^"]+" payment)$/ * @Given /^I chose ("[^"]+" shipping method) with ("[^"]+" payment)$/ */ public function theCustomerChoseShippingWithPayment(ShippingMethodInterface $shippingMethod, PaymentMethodInterface $paymentMethod) { /** @var OrderInterface $order */ $order = $this->sharedStorage->get('order'); $this->orderProcessor->process($order); $order->getShipments()->first()->setMethod($shippingMethod); $this->applyTransitionOnOrderCheckout($order, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING); $payment = $order->getLastPayment(); $payment->setMethod($paymentMethod); $this->applyTransitionOnOrderCheckout($order, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT); $this->applyTransitionOnOrderCheckout($order, OrderCheckoutTransitions::TRANSITION_COMPLETE); $this->objectManager->flush(); }
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_uses_order_processor_to_recalculate_order(OrderProcessorInterface $orderProcessor, GenericEvent $event, OrderInterface $order) { $event->getSubject()->willReturn($order); $orderProcessor->process($order)->shouldBeCalled(); $this->recalculateOrder($event); }