- 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.
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Models\ValueObjects;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Carbon\CarbonInterface;
|
|
use Domain\Models\Entities\PickupExceptionOnDate;
|
|
|
|
final readonly class ShopPickupOverride
|
|
{
|
|
public function __construct(
|
|
public PickupExceptionOnDate $exception,
|
|
public ?CarbonInterface $replacementDate = null,
|
|
public ?CarbonInterface $orderDeadlineAt = null
|
|
) {
|
|
if ($orderDeadlineAt !== null && $replacementDate !== null && $orderDeadlineAt->greaterThanOrEqualTo($replacementDate)) {
|
|
throw new \DomainException(
|
|
'Order deadline must be strictly before the replacement date'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function hasReplacement(): bool
|
|
{
|
|
return $this->replacementDate !== null;
|
|
}
|
|
|
|
public function effectiveDeadline(CarbonInterface $defaultDeadline): CarbonImmutable
|
|
{
|
|
return $this->orderDeadlineAt !== null
|
|
? CarbonImmutable::createFromInterface($this->orderDeadlineAt)
|
|
: CarbonImmutable::createFromInterface($defaultDeadline);
|
|
}
|
|
|
|
public function isDeadlinePassed(CarbonInterface $now, CarbonInterface $defaultDeadline): bool
|
|
{
|
|
return $now->greaterThan($this->effectiveDeadline($defaultDeadline));
|
|
}
|
|
}
|