feat(29-delivery-status-mapping-ui): konfiguracja mapowania statusów dostawy per provider
Phase 29 complete (v1.3): - Tabela delivery_status_mappings z DB overrides - DeliveryStatus: normalizeWithOverrides(), descriptionWithOverrides(), getDefaultMappings() - UI ustawień: tabela mapowań per provider (InPost/Apaczka/Allegro), bulk save, reset, resetAll - 5 endpointów w routes/web.php, link w menu bocznym Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -191,6 +191,76 @@ final class DeliveryStatus
|
||||
'RETURNED' => 'Zwrócona do nadawcy',
|
||||
];
|
||||
|
||||
public const ALL_STATUSES = [
|
||||
self::UNKNOWN,
|
||||
self::CREATED,
|
||||
self::CONFIRMED,
|
||||
self::IN_TRANSIT,
|
||||
self::OUT_FOR_DELIVERY,
|
||||
self::READY_FOR_PICKUP,
|
||||
self::DELIVERED,
|
||||
self::RETURNED,
|
||||
self::CANCELLED,
|
||||
self::PROBLEM,
|
||||
];
|
||||
|
||||
private const PROVIDER_MAPS = [
|
||||
'inpost' => self::INPOST_MAP,
|
||||
'apaczka' => self::APACZKA_MAP,
|
||||
'allegro_wza' => self::ALLEGRO_MAP,
|
||||
];
|
||||
|
||||
private const PROVIDER_DESCRIPTIONS = [
|
||||
'inpost' => self::INPOST_DESCRIPTIONS,
|
||||
'apaczka' => self::APACZKA_DESCRIPTIONS,
|
||||
'allegro_wza' => self::ALLEGRO_DESCRIPTIONS,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, array{normalized: string, description: string}>
|
||||
*/
|
||||
public static function getDefaultMappings(string $provider): array
|
||||
{
|
||||
$map = self::PROVIDER_MAPS[$provider] ?? [];
|
||||
$descriptions = self::PROVIDER_DESCRIPTIONS[$provider] ?? [];
|
||||
|
||||
$result = [];
|
||||
foreach ($map as $rawStatus => $normalized) {
|
||||
$result[(string) $rawStatus] = [
|
||||
'normalized' => $normalized,
|
||||
'description' => (string) ($descriptions[$rawStatus] ?? (string) $rawStatus),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array{normalized_status: string, description: string}> $overrides keyed by "provider:raw_status"
|
||||
*/
|
||||
public static function normalizeWithOverrides(string $provider, string $rawStatus, array $overrides): string
|
||||
{
|
||||
$key = $provider . ':' . $rawStatus;
|
||||
if (isset($overrides[$key]) && $overrides[$key]['normalized_status'] !== '') {
|
||||
return $overrides[$key]['normalized_status'];
|
||||
}
|
||||
|
||||
return self::normalize($provider, $rawStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array{normalized_status: string, description: string}> $overrides keyed by "provider:raw_status"
|
||||
*/
|
||||
public static function descriptionWithOverrides(string $provider, string $rawStatus, array $overrides): string
|
||||
{
|
||||
$key = $provider . ':' . $rawStatus;
|
||||
if (isset($overrides[$key]) && $overrides[$key]['description'] !== '') {
|
||||
return $overrides[$key]['description'];
|
||||
}
|
||||
|
||||
return self::description($provider, $rawStatus);
|
||||
}
|
||||
|
||||
public static function normalize(string $provider, string $rawStatus): string
|
||||
{
|
||||
$map = match ($provider) {
|
||||
|
||||
Reference in New Issue
Block a user