ldc-boutique-cnc-sable/domain/Events/Dto/OrderPlacedLine.php
Jérémy Munsch c40016bba1
feat(order): implement order placement and related DTOs
- Add methods to convert OrderLine and DeliveryAddress to DTOs.
- Introduce toPlacedEvent method in Order to generate domain event.
- Enhance OrderUnit with Regate code mapping.
- Implement tests for new functionality and ensure correctness.
2026-10-29 20:35:13 +01:00

40 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Domain\Events\Dto;
use Domain\Enums\Units\OrderUnit;
use Domain\Models\ValueObjects\IncoId;
use Domain\Models\ValueObjects\OrderLine;
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
);
}
}