This commit is contained in:
2026-04-22 22:54:26 +02:00
parent cd1ea4a9db
commit c73b2fe9f6
26 changed files with 1377 additions and 34 deletions

View File

@@ -47,6 +47,7 @@ use App\Modules\Settings\ShopproStatusMappingRepository;
use App\Modules\Settings\ShopproStatusSyncService;
use App\Modules\Shipments\AllegroTrackingService;
use App\Modules\Shipments\ApaczkaTrackingService;
use App\Modules\Shipments\DeliveryStatusMappingRepository;
use App\Modules\Shipments\InpostTrackingService;
use App\Modules\Shipments\ShipmentPackageRepository;
use App\Modules\Shipments\ShipmentTrackingRegistry;
@@ -173,7 +174,8 @@ final class CronHandlerFactory
),
]),
new ShipmentPackageRepository($this->db),
$automationService
$automationService,
new DeliveryStatusMappingRepository($this->db)
),
'automation_history_cleanup' => new AutomationHistoryCleanupHandler(
new AutomationExecutionLogRepository($this->db)

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\Modules\Cron;
use App\Modules\Automation\AutomationService;
use App\Modules\Shipments\DeliveryStatus;
use App\Modules\Shipments\DeliveryStatusMappingRepository;
use App\Modules\Shipments\ShipmentPackageRepository;
use App\Modules\Shipments\ShipmentTrackingRegistry;
use Throwable;
@@ -15,7 +17,8 @@ final class ShipmentTrackingHandler
public function __construct(
private readonly ShipmentTrackingRegistry $registry,
private readonly ShipmentPackageRepository $repository,
private readonly AutomationService $automationService
private readonly AutomationService $automationService,
private readonly ?DeliveryStatusMappingRepository $mappingRepository = null
) {
}
@@ -32,6 +35,10 @@ final class ShipmentTrackingHandler
$lastAllegroEdgeRequestTime = 0.0;
$overrides = $this->mappingRepository !== null
? $this->mappingRepository->getAllOverrides()
: [];
foreach ($packages as $package) {
$provider = trim((string) ($package['provider'] ?? ''));
$packageId = (int) ($package['id'] ?? 0);
@@ -68,6 +75,12 @@ final class ShipmentTrackingHandler
$newStatus = 'unknown';
}
$newStatusRaw = trim((string) ($result['status_raw'] ?? ''));
// Zastosuj override z DB (delivery_status_mappings) jesli istnieje dla (provider, raw).
// Dzieki temu admin moze bez zmian w kodzie przypisac nowe statusy kuriera przez UI.
if ($newStatusRaw !== '' && $overrides !== []) {
$newStatus = DeliveryStatus::normalizeWithOverrides($provider, $newStatusRaw, $overrides);
}
$statusChanged = $newStatus !== $previousStatus;
$statusRawChanged = $newStatusRaw !== $previousStatusRaw;
if (!$statusChanged && !$statusRawChanged) {