feat: Implement Allegro Order Sync and Status Management

- Added AllegroOrderSyncStateRepository for managing sync state with Allegro orders.
- Introduced AllegroOrdersSyncService to handle the synchronization of orders from Allegro.
- Created AllegroStatusDiscoveryService to discover and store order statuses from Allegro.
- Developed AllegroStatusMappingRepository for managing status mappings between Allegro and OrderPro.
- Implemented AllegroStatusSyncService to facilitate status synchronization.
- Added CronSettingsController for managing cron job settings related to Allegro integration.
This commit is contained in:
2026-03-04 23:21:35 +01:00
parent 9ca79ca8d8
commit 7ac4293df4
40 changed files with 5758 additions and 31 deletions

View File

@@ -39,11 +39,11 @@ final class OrdersController
$result = $this->orders->paginate($filters);
$totalPages = max(1, (int) ceil(((int) $result['total']) / max(1, (int) $result['per_page'])));
$sourceOptions = $this->orders->sourceOptions();
$statusOptions = $this->orders->statusOptions();
$stats = $this->orders->quickStats();
$statusCounts = $this->orders->statusCounts();
$statusConfig = $this->orders->statusPanelConfig();
$statusLabelMap = $this->statusLabelMap($statusConfig);
$statusOptions = $this->buildStatusFilterOptions($this->orders->statusOptions(), $statusLabelMap);
$statusPanel = $this->buildStatusPanel($statusConfig, $statusCounts, $filters['status'], $filters);
$tableRows = array_map(fn (array $row): array => $this->toTableRow($row, $statusLabelMap), (array) ($result['items'] ?? []));
@@ -144,7 +144,7 @@ final class OrdersController
$documents = is_array($details['documents'] ?? null) ? $details['documents'] : [];
$notes = is_array($details['notes'] ?? null) ? $details['notes'] : [];
$history = is_array($details['status_history'] ?? null) ? $details['status_history'] : [];
$statusCode = (string) ($order['external_status_id'] ?? '');
$statusCode = (string) (($order['effective_status_id'] ?? '') !== '' ? $order['effective_status_id'] : ($order['external_status_id'] ?? ''));
$statusCounts = $this->orders->statusCounts();
$statusConfig = $this->orders->statusPanelConfig();
$statusLabelMap = $this->statusLabelMap($statusConfig);
@@ -183,7 +183,7 @@ final class OrdersController
$buyerName = trim((string) ($row['buyer_name'] ?? ''));
$buyerEmail = trim((string) ($row['buyer_email'] ?? ''));
$buyerCity = trim((string) ($row['buyer_city'] ?? ''));
$status = trim((string) ($row['external_status_id'] ?? ''));
$status = trim((string) (($row['effective_status_id'] ?? '') !== '' ? $row['effective_status_id'] : ($row['external_status_id'] ?? '')));
$currency = trim((string) ($row['currency'] ?? ''));
$totalWithTax = $row['total_with_tax'] !== null ? number_format((float) $row['total_with_tax'], 2, '.', ' ') : '-';
$totalPaid = $row['total_paid'] !== null ? number_format((float) $row['total_paid'], 2, '.', ' ') : '-';
@@ -211,7 +211,7 @@ final class OrdersController
. '</div>'
. '</div>',
'status_badges' => '<div class="orders-status-wrap">'
. $this->statusBadge($this->statusLabel($status, $statusLabelMap))
. $this->statusBadge($status, $this->statusLabel($status, $statusLabelMap))
. '</div>',
'products' => $this->productsHtml($itemsPreview, $itemsCount, $itemsQty),
'totals' => '<div class="orders-money">'
@@ -227,17 +227,18 @@ final class OrdersController
];
}
private function statusBadge(string $status): string
private function statusBadge(string $statusCode, string $statusLabel): string
{
$label = $status !== '' ? $status : '-';
$label = $statusLabel !== '' ? $statusLabel : '-';
$code = strtolower(trim($statusCode));
$class = 'is-neutral';
if (in_array($status, ['shipped', 'delivered'], true)) {
if (in_array($code, ['shipped', 'delivered'], true)) {
$class = 'is-success';
} elseif (in_array($status, ['cancelled', 'returned'], true)) {
} elseif (in_array($code, ['cancelled', 'returned'], true)) {
$class = 'is-danger';
} elseif (in_array($status, ['new', 'confirmed'], true)) {
} elseif (in_array($code, ['new', 'confirmed'], true)) {
$class = 'is-info';
} elseif (in_array($status, ['processing', 'packed', 'paid'], true)) {
} elseif (in_array($code, ['processing', 'packed', 'paid'], true)) {
$class = 'is-warn';
}
@@ -255,7 +256,8 @@ final class OrdersController
return (string) $statusLabelMap[$key];
}
return ucfirst($statusCode);
$normalized = str_replace(['_', '-'], ' ', $key);
return ucfirst($normalized);
}
/**
@@ -415,6 +417,26 @@ final class OrdersController
return $map;
}
/**
* @param array<string, string> $statusCodes
* @param array<string, string> $statusLabelMap
* @return array<string, string>
*/
private function buildStatusFilterOptions(array $statusCodes, array $statusLabelMap): array
{
$options = [];
foreach ($statusCodes as $code => $value) {
$rawCode = trim((string) ($code !== '' ? $code : $value));
if ($rawCode === '') {
continue;
}
$normalizedCode = strtolower($rawCode);
$options[$normalizedCode] = $this->statusLabel($normalizedCode, $statusLabelMap);
}
return $options;
}
/**
* @param array<int, array<string, mixed>> $itemsPreview
*/