*/ public array $options = [] ) { if (trim($name) === '') { throw new \DomainException('name cannot be empty'); } if (trim($slug) === '') { throw new \DomainException('slug cannot be empty'); } if ($qty <= 0) { throw new \DomainException('qty has to be positive'); } if (! $unitPriceHt->isPositive()) { throw new \DomainException('unitPriceHt has to be positive'); } if (! $unitDiscount->isPositive() && ! $unitDiscount->isZero()) { throw new \DomainException('unitDiscount cannot be negative'); } if (! $priceKgTtc->isPositive()) { throw new \DomainException('priceKgTtc has to be positive'); } } public function unitPriceHt(): Money { return $this->unitPriceHt; } public function unitPriceDiscounted(): Money { return $this->unitPriceHt->subtract($this->unitDiscount); } public function unitTax(): Money { return $this->unitTtc()->subtract($this->unitPriceDiscounted()); } public function unitTtc(): Money { return $this->taxRate->applyTo($this->unitPriceDiscounted()); } public function discountTotal(): Money { return $this->unitDiscount->multiply($this->qty, Product::ROUNDING); } public function priceTotalHt(): Money { return $this->unitPriceHt->multiply($this->qty, Product::ROUNDING); } public function subtotalHt(): Money { return $this->priceTotalHt()->subtract($this->discountTotal()); } public function taxTotal(): Money { return $this->totalTtc()->subtract($this->subtotalHt()); } public function totalTtc(): Money { return $this->taxRate->applyTo($this->subtotalHt()); } public function weightTotal(): int { return $this->weightGrams * $this->qty; } }