This commit is contained in:
2026-03-14 01:10:29 +01:00
parent ac0e07916e
commit 62a68e9ec2
23 changed files with 908 additions and 239 deletions

View File

@@ -47,10 +47,11 @@ final class OrdersController
$statusCounts = $this->orders->statusCounts();
$statusConfig = $this->orders->statusPanelConfig();
$statusLabelMap = $this->statusLabelMap($statusConfig);
$statusColorMap = $this->statusColorMap($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'] ?? []));
$tableRows = array_map(fn (array $row): array => $this->toTableRow($row, $statusLabelMap, $statusColorMap), (array) ($result['items'] ?? []));
$html = $this->template->render('orders/list', [
'title' => $this->translator->get('orders.title'),
@@ -228,7 +229,7 @@ final class OrdersController
* @param array<string, mixed> $row
* @return array<string, mixed>
*/
private function toTableRow(array $row, array $statusLabelMap): array
private function toTableRow(array $row, array $statusLabelMap, array $statusColorMap = []): array
{
$internalOrderNumber = trim((string) ($row['internal_order_number'] ?? ''));
$sourceOrderId = trim((string) ($row['source_order_id'] ?? ''));
@@ -257,8 +258,8 @@ final class OrdersController
. htmlspecialchars($internalOrderNumber !== '' ? $internalOrderNumber : ('#' . (string) ($row['id'] ?? 0)), ENT_QUOTES, 'UTF-8')
. '</a></div>'
. '<div class="orders-ref__meta">'
. '<span>' . htmlspecialchars($sourceOrderId !== '' ? $sourceOrderId : $externalOrderId, ENT_QUOTES, 'UTF-8') . '</span>'
. '<span>' . htmlspecialchars($source, ENT_QUOTES, 'UTF-8') . '</span>'
. '<span>' . htmlspecialchars($this->sourceLabel($source), ENT_QUOTES, 'UTF-8') . '</span>'
. '<span>ID: ' . htmlspecialchars($sourceOrderId !== '' ? $sourceOrderId : $externalOrderId, ENT_QUOTES, 'UTF-8') . '</span>'
. '</div>'
. '</div>',
'buyer' => '<div class="orders-buyer">'
@@ -269,7 +270,7 @@ final class OrdersController
. '</div>'
. '</div>',
'status_badges' => '<div class="orders-status-wrap">'
. $this->statusBadge($status, $this->statusLabel($status, $statusLabelMap))
. $this->statusBadge($status, $this->statusLabel($status, $statusLabelMap), $statusColorMap[strtolower(trim($status))] ?? '')
. '</div>',
'products' => $this->productsHtml($itemsPreview, $itemsCount, $itemsQty),
'totals' => '<div class="orders-money">'
@@ -285,10 +286,16 @@ final class OrdersController
];
}
private function statusBadge(string $statusCode, string $statusLabel): string
private function statusBadge(string $statusCode, string $statusLabel, string $colorHex = ''): string
{
$label = $statusLabel !== '' ? $statusLabel : '-';
$code = strtolower(trim($statusCode));
if ($colorHex !== '') {
$style = 'background-color:' . htmlspecialchars($colorHex, ENT_QUOTES, 'UTF-8') . ';color:#fff';
return '<span class="order-tag" style="' . $style . '">' . htmlspecialchars($label, ENT_QUOTES, 'UTF-8') . '</span>';
}
$class = 'is-neutral';
if (in_array($code, ['shipped', 'delivered'], true)) {
$class = 'is-success';
@@ -303,6 +310,16 @@ final class OrdersController
return '<span class="order-tag ' . $class . '">' . htmlspecialchars($label, ENT_QUOTES, 'UTF-8') . '</span>';
}
private function sourceLabel(string $source): string
{
return match (strtolower(trim($source))) {
'allegro' => 'Allegro',
'shoppro' => 'shopPRO',
'erli' => 'Erli',
default => ucfirst(strtolower(trim($source))),
};
}
private function statusLabel(string $statusCode, array $statusLabelMap = []): string
{
$key = strtolower(trim($statusCode));
@@ -475,6 +492,30 @@ final class OrdersController
return $map;
}
/**
* @param array<int, array{name:string,color_hex:string,items:array<int, array{code:string,name:string}>}> $config
* @return array<string, string>
*/
private function statusColorMap(array $config): array
{
$map = [];
foreach ($config as $group) {
$groupColor = StringHelper::normalizeColorHex((string) ($group['color_hex'] ?? ''));
if ($groupColor === '') {
continue;
}
$items = is_array($group['items'] ?? null) ? $group['items'] : [];
foreach ($items as $item) {
$code = strtolower(trim((string) ($item['code'] ?? '')));
if ($code !== '') {
$map[$code] = $groupColor;
}
}
}
return $map;
}
/**
* @param array<string, string> $statusCodes
* @param array<string, string> $statusLabelMap