isNegative()) { throw new \DomainException('Product price cannot be negative'); } if ($discountedPrice->isNegative()) { throw new \DomainException('Product discounted price cannot be negative'); } if ($priceKgTtc->isNegative()) { throw new \DomainException('Price per kg TTC cannot be negative'); } if ($discountedPrice->greaterThan($price)) { throw new \DomainException('Product discounted price cannot be greater than original price'); } if (! $priceKgTtc->isPositive()) { throw new \DomainException('Price per kg TTC has to be positive'); } } public static function fromBasketProduct(BasketProduct $item): self { return new self( 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->unitPriceDiscounted(), priceKgTtc: clone $item->priceKgTtc, taxRate: $item->taxRate, picture: $item->picture ); } }