/** * @param NewCheckout $command * @throws CheckoutAlreadyExistsException * @throws InvalidArgumentException * @throws CartNotFoundException * @throws InvalidUUIDFormatException */ public function handle(NewCheckout $command) { $cartId = new CartId($command->cartId()); if (!$this->carts->exists($cartId)) { throw new CartNotFoundException(); } $billingAddress = new Address($command->name(), $command->street(), $command->postCode(), $command->city(), $command->countryIso2Code()); if ($this->checkouts->existsForCart($cartId)) { throw new CheckoutAlreadyExistsException(); } $this->checkouts->add(new Checkout($cartId, $billingAddress)); }
/** * @param PlaceOrder $command * @throws OrderAlreadyExistsException * @throws \Dumplie\Customer\Domain\Exception\EmptyCartException */ public function handle(PlaceOrder $command) { $cartId = new CartId($command->cartId()); $orderId = new OrderId($command->orderId()); if ($this->orders->exists($orderId)) { throw OrderAlreadyExistsException::withId($orderId); } $checkout = $this->checkouts->getForCart($cartId); $order = $checkout->placeOrder($orderId, $this->products, $this->carts); $this->orders->add($order); $this->checkouts->removeForCart($cartId); $this->carts->remove($cartId); $this->eventLog->log(new CustomerPlacedOrder((string) $orderId)); }
/** * @param ChangeShippingAddress $command * @throws InvalidArgumentException */ public function handle(ChangeShippingAddress $command) { $shippingAddress = new Address($command->name(), $command->street(), $command->postCode(), $command->city(), $command->countryIso2Code()); $checkout = $this->checkouts->getForCart(new CartId($command->cartId())); $checkout->changeShippingAddress($shippingAddress); }