update
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -9,7 +9,7 @@ use Throwable;
|
||||
|
||||
final class OrdersRepository
|
||||
{
|
||||
private ?bool $supportsMappedMedia = null;
|
||||
private static ?bool $supportsMappedMedia = null;
|
||||
|
||||
public function __construct(private readonly PDO $pdo)
|
||||
{
|
||||
@@ -158,13 +158,25 @@ final class OrdersRepository
|
||||
a.city AS buyer_city,
|
||||
o.external_carrier_id,
|
||||
o.external_payment_type_id,
|
||||
(SELECT COUNT(*) FROM order_items oi WHERE oi.order_id = o.id) AS items_count,
|
||||
(SELECT COALESCE(SUM(oi.quantity), 0) FROM order_items oi WHERE oi.order_id = o.id) AS items_qty,
|
||||
(SELECT COUNT(*) FROM order_shipments sh WHERE sh.order_id = o.id) AS shipments_count,
|
||||
(SELECT COUNT(*) FROM order_documents od WHERE od.order_id = o.id) AS documents_count
|
||||
COALESCE(oi_agg.items_count, 0) AS items_count,
|
||||
COALESCE(oi_agg.items_qty, 0) AS items_qty,
|
||||
COALESCE(sh_agg.shipments_count, 0) AS shipments_count,
|
||||
COALESCE(od_agg.documents_count, 0) AS documents_count
|
||||
FROM orders o
|
||||
LEFT JOIN order_addresses a ON a.order_id = o.id AND a.address_type = "customer"
|
||||
LEFT JOIN allegro_order_status_mappings asm ON o.source = "allegro" AND LOWER(o.external_status_id) = asm.allegro_status_code'
|
||||
LEFT JOIN allegro_order_status_mappings asm ON o.source = "allegro" AND LOWER(o.external_status_id) = asm.allegro_status_code
|
||||
LEFT JOIN (
|
||||
SELECT order_id, COUNT(*) AS items_count, COALESCE(SUM(quantity), 0) AS items_qty
|
||||
FROM order_items GROUP BY order_id
|
||||
) oi_agg ON oi_agg.order_id = o.id
|
||||
LEFT JOIN (
|
||||
SELECT order_id, COUNT(*) AS shipments_count
|
||||
FROM order_shipments GROUP BY order_id
|
||||
) sh_agg ON sh_agg.order_id = o.id
|
||||
LEFT JOIN (
|
||||
SELECT order_id, COUNT(*) AS documents_count
|
||||
FROM order_documents GROUP BY order_id
|
||||
) od_agg ON od_agg.order_id = o.id'
|
||||
. $whereSql
|
||||
. ' ORDER BY ' . $sortColumn . ' ' . $sortDir
|
||||
. ' LIMIT :limit OFFSET :offset';
|
||||
@@ -646,8 +658,8 @@ final class OrdersRepository
|
||||
|
||||
private function canResolveMappedMedia(): bool
|
||||
{
|
||||
if ($this->supportsMappedMedia !== null) {
|
||||
return $this->supportsMappedMedia;
|
||||
if (self::$supportsMappedMedia !== null) {
|
||||
return self::$supportsMappedMedia;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -682,12 +694,12 @@ final class OrdersRepository
|
||||
$stmt->execute($params);
|
||||
$count = (int) $stmt->fetchColumn();
|
||||
|
||||
$this->supportsMappedMedia = ($count === count($requiredColumns));
|
||||
self::$supportsMappedMedia = ($count === count($requiredColumns));
|
||||
} catch (Throwable) {
|
||||
$this->supportsMappedMedia = false;
|
||||
self::$supportsMappedMedia = false;
|
||||
}
|
||||
|
||||
return $this->supportsMappedMedia;
|
||||
return self::$supportsMappedMedia;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user