feat: Enhance order date handling with effective date fallback and update documentation

This commit is contained in:
2026-03-04 23:56:45 +01:00
parent 7ac4293df4
commit 9df7a63244
6 changed files with 237 additions and 41 deletions

View File

@@ -27,6 +27,7 @@ final class OrdersRepository
$where = [];
$params = [];
$effectiveStatusSql = $this->effectiveStatusSql('o', 'asm');
$effectiveOrderedAtSql = $this->effectiveOrderedAtSql('o');
$search = trim((string) ($filters['search'] ?? ''));
if ($search !== '') {
@@ -60,13 +61,13 @@ final class OrdersRepository
$dateFrom = trim((string) ($filters['date_from'] ?? ''));
if ($dateFrom !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateFrom) === 1) {
$where[] = 'o.ordered_at >= :date_from';
$where[] = $effectiveOrderedAtSql . ' >= :date_from';
$params['date_from'] = $dateFrom . ' 00:00:00';
}
$dateTo = trim((string) ($filters['date_to'] ?? ''));
if ($dateTo !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateTo) === 1) {
$where[] = 'o.ordered_at <= :date_to';
$where[] = $effectiveOrderedAtSql . ' <= :date_to';
$params['date_to'] = $dateTo . ' 23:59:59';
}
@@ -84,7 +85,7 @@ final class OrdersRepository
'source_updated_at' => 'o.source_updated_at',
'fetched_at' => 'o.fetched_at',
'id' => 'o.id',
default => 'o.ordered_at',
default => $effectiveOrderedAtSql,
};
try {
@@ -108,8 +109,10 @@ final class OrdersRepository
o.total_with_tax,
o.total_paid,
o.ordered_at,
o.source_created_at,
o.source_updated_at,
o.fetched_at,
' . $effectiveOrderedAtSql . ' AS effective_ordered_at,
o.is_invoice,
o.is_canceled_by_buyer,
a.name AS buyer_name,
@@ -161,7 +164,8 @@ final class OrdersRepository
'currency' => (string) ($row['currency'] ?? ''),
'total_with_tax' => $row['total_with_tax'] !== null ? (float) $row['total_with_tax'] : null,
'total_paid' => $row['total_paid'] !== null ? (float) $row['total_paid'] : null,
'ordered_at' => (string) ($row['ordered_at'] ?? ''),
'ordered_at' => (string) ($row['effective_ordered_at'] ?? ''),
'source_created_at' => (string) ($row['source_created_at'] ?? ''),
'source_updated_at' => (string) ($row['source_updated_at'] ?? ''),
'fetched_at' => (string) ($row['fetched_at'] ?? ''),
'is_invoice' => (int) ($row['is_invoice'] ?? 0) === 1,
@@ -551,6 +555,16 @@ final class OrdersRepository
END';
}
private function effectiveOrderedAtSql(string $orderAlias): string
{
return 'COALESCE('
. $orderAlias . '.ordered_at, '
. $orderAlias . '.source_created_at, '
. $orderAlias . '.source_updated_at, '
. $orderAlias . '.fetched_at'
. ')';
}
private function resolvedMediaUrlSql(string $itemAlias): string
{
if (!$this->canResolveMappedMedia()) {