public function createOrder(CreateOrderCommand $command) { $cart = $this->cartRepository->getCart(); if ($cart->getLineItems()->count() === 0) { throw new \RuntimeException("The cart is empty"); } $address = $command->getAddress(); $order = new Order(new UuidIdentity(Uuid::uuid4()), $this->tokenStorage->getToken()->getUser(), new Address($address->getCountry(), $address->getCity(), $address->getStreet(), $address->getZipCode())); foreach ($cart->getLineItems() as $lineItem) { $order->addProduct($lineItem->getProduct(), $lineItem->getQuantity()); } $this->orderRepository->save($order); $event = new OrderCreatedEvent($order, $command->getGatewayName()); $this->eventBus->handle($event); }
public function removeProduct(RemoveProductCommand $command) { $cart = $this->repository->getCart(); $cart->removeProduct(new UuidIdentity($command->getId())); $this->repository->setCart($cart); }