- 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.
40 lines
1.1 KiB
PHP
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
|
|
);
|
|
}
|
|
}
|