items() as $item) { $orderLineProduct = new OrderLineProduct( incoId: $item->incoId ?? throw new \DomainException('incoId cannot be null for an order'), originalId: $item->id, name: $item->name, weight: new ProductWeight($item->weightGrams, $item->weightVariable), brand: $item->brand ?? ProductBrand::none, orderUnit: $item->orderUnit, price: clone $item->unitPriceHt, discountedPrice: $item->unitPriceHt->subtract($item->unitDiscount), priceKgTtc: clone $item->priceKgTtc, taxRate: $item->taxRate, picture: $item->picture ); $lines[] = new OrderLine( product: $orderLineProduct, quantity: $item->qty, unitPriceHt: clone $item->unitPriceHt, unitDiscount: clone $item->unitDiscount, unitTax: clone $item->taxRate ->applyTo($item->unitPriceHt ->subtract($item->unitDiscount)) ->subtract($item->unitPriceHt ->subtract($item->unitDiscount)), totalHt: clone $item->subtotalHt(), totalDiscount: clone $item->discountTotal(), totalTax: clone $item->taxTotal(), totalTtc: clone $item->totalTtc() ); } return new Order( id: $this->newOrderId(), shopId: clone $shop->id(), reference: $this->newReference(), employee: new OrderEmployee( matricule: clone $shopper->matricule, firstname: $shopper->prenom, lastname: $shopper->nom, facility: $shopper->etablissement, site: $shopper->site, service: $shopper->service ), deliveryAddress: new DeliveryAddress( name: $shop->name, address: $shop->address, postcode: $shop->postcode, city: $shop->city, phone: $shop->phone ), pickupTimeSlot: clone $pickupTimeSlot, status: OrderStatus::VALIDATED, total: clone $basket->totalTaxIncluded(), lines: $lines ); } private function newOrderId(): OrderId { return new OrderId(Uuid::uuid7()); } private function newReference(): OrderReference { return new OrderReference( $this->uuidConverter->toBase58( Uuid::uuid7() ) ); } public function cancelOrder(OrderId $id): void { $order = $this->orderRepository->find($id); if (! $order) { throw new \DomainException('Order not found'); } $order->cancel(); $this->orderRepository->persist($order); } }