Beispiel #1
0
 function it_can_be_used_to_place_order(Products $products, Carts $carts)
 {
     $product = new Product(new SKU("SKU"), Price::EUR(1000), true);
     $cart = new Cart(CartId::generate(), 'EUR');
     $cart->add($product, 1);
     $carts->getById(Argument::type(CartId::class))->willReturn($cart);
     $products->getBySku(Argument::type(SKU::class))->willReturn($product);
     $order = $this->placeOrder(OrderId::generate(), $products, $carts);
     $order->shouldBeAnInstanceOf(Order::class);
 }
Beispiel #2
0
 /**
  * @param OrderId $id
  * @param Products $products
  * @param Carts $carts
  * @return Order
  * @throws EmptyCartException
  * @throws ProductNotFoundException
  */
 public function placeOrder(OrderId $id, Products $products, Carts $carts) : Order
 {
     $cart = $carts->getById($this->cartId());
     if ($cart->isEmpty()) {
         throw new EmptyCartException();
     }
     $orderItems = [];
     foreach ($cart->items() as $item) {
         $product = $products->getBySku($item->sku());
         $orderItems[] = OrderItem::createFromProduct($product, $item->quantity());
     }
     return new Order($id, $orderItems, $this->billingAddress(), $this->shippingAddress());
 }
Beispiel #3
0
 /**
  * @param AddToCart $command
  *
  * @throws \Exception
  */
 public function handle(AddToCart $command)
 {
     $product = $this->products->getBySku(new SKU($command->sku()));
     $cart = $this->carts->getById(new CartId($command->cartId()));
     $cart->add($product, $command->quantity());
 }