ldc-boutique-cnc-sable/domain/Events/Dto/OrderPlacedLine.php

41 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Domain\Events\Dto;
use Domain\Enums\Units\OrderUnit;
use Domain\Models\ValueObjects\IncoId;
use Domain\Models\ValueObjects\OrderLine;
2026-06-14 21:32:07 +02:00
use Money\Money;
final readonly class OrderPlacedLine
{
public function __construct(
public string $productName,
public IncoId $productIncoId,
public bool $productWeightIsVariable,
public ?Money $productPriceKgTtc,
public OrderUnit $productOrderUnit,
public int $quantity,
public Money $totalTtc,
) {
if ($quantity <= 0) {
throw new \DomainException('Quantity must be greater than 0');
}
}
public static function fromOrderLine(OrderLine $line): self
{
return new self(
productName: $line->product->name,
productIncoId: clone $line->product->incoId,
productWeightIsVariable: $line->product->weight->isVariable,
productPriceKgTtc: clone $line->product->priceKgTtc,
productOrderUnit: $line->product->orderUnit,
quantity: $line->quantity,
totalTtc: clone $line->totalTtc
);
}
2026-06-14 21:32:07 +02:00
}