ldc-boutique-cnc-sable/domain/Models/ValueObjects/ShopPickupOverride.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

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));
}
}