function it_recalculates_cart_for_logged_in_user(CartProviderInterface $cartProvider, Event $event, OrderInterface $order, OrderRecalculatorInterface $orderRecalculator)
 {
     $cartProvider->hasCart()->willReturn(true);
     $cartProvider->getCart()->willReturn($order);
     $orderRecalculator->recalculate($order)->shouldBeCalled();
     $this->recalculateCartWhileLogin($event);
 }
 /**
  * @param GenericEvent $event
  *
  * @throws UnexpectedTypeException
  */
 public function recalculateOrder(GenericEvent $event)
 {
     $order = $event->getSubject();
     if (!$order instanceof OrderInterface) {
         throw new UnexpectedTypeException($order, OrderInterface::class);
     }
     $this->orderRecalculator->recalculate($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->orderRecalculator->recalculate($cart);
 }
Ejemplo n.º 4
0
 /**
  * @param ProductVariantInterface $productVariant
  * @param int $price
  * @param int $quantity
  *
  * @return OrderInterface
  */
 private function addProductVariantToOrder(ProductVariantInterface $productVariant, $price, $quantity = 1)
 {
     $order = $this->sharedStorage->get('order');
     /** @var OrderItemInterface $item */
     $item = $this->orderItemFactory->createNew();
     $item->setVariant($productVariant);
     $item->setUnitPrice($productVariant->getPrice());
     $this->itemQuantityModifier->modify($item, $quantity);
     $order->addItem($item);
     $this->orderRecalculator->recalculate($order);
     return $order;
 }
Ejemplo n.º 5
0
 function it_adds_single_item_by_customer_and_applies_a_coupon(FactoryInterface $orderItemFactory, OrderInterface $order, OrderItemInterface $item, OrderItemQuantityModifierInterface $itemQuantityModifier, ProductInterface $product, CouponInterface $coupon, SharedStorageInterface $sharedStorage, ProductVariantInterface $variant, OrderRecalculatorInterface $orderRecalculator, ObjectManager $objectManager)
 {
     $sharedStorage->get('order')->willReturn($order);
     $orderItemFactory->createNew()->willReturn($item);
     $product->getMasterVariant()->willReturn($variant);
     $product->getPrice()->willReturn(1234);
     $itemQuantityModifier->modify($item, 1)->shouldBeCalled();
     $item->setVariant($variant)->shouldBeCalled();
     $item->setUnitPrice(1234)->shouldBeCalled();
     $order->setPromotionCoupon($coupon)->shouldBeCalled();
     $order->addItem($item)->shouldBeCalled();
     $orderRecalculator->recalculate($order)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->theCustomerBoughtSingleUsing($product, $coupon);
 }
 function it_uses_order_recalculator_to_recalculate_order(GenericEvent $event, OrderInterface $order, OrderRecalculatorInterface $orderRecalculator)
 {
     $event->getSubject()->willReturn($order);
     $orderRecalculator->recalculate($order)->shouldBeCalled();
     $this->recalculateOrder($event);
 }
 function it_does_nothing_if_cannot_find_cart(CartContextInterface $cartContext, OrderRecalculatorInterface $orderRecalculator, Event $event)
 {
     $cartContext->getCart()->willThrow(CartNotFoundException::class);
     $orderRecalculator->recalculate(Argument::any())->shouldNotBeCalled();
     $this->recalculateCartWhileLogin($event);
 }