diff --git a/classes/Carrier/SendCloud/SendCloudApi.php b/classes/Carrier/SendCloud/SendCloudApi.php index 7ae71daa..be52229e 100644 --- a/classes/Carrier/SendCloud/SendCloudApi.php +++ b/classes/Carrier/SendCloud/SendCloudApi.php @@ -1,7 +1,7 @@ sendRequest($uri); + $highest = null; + foreach ($response['body']->statuses as $status) { + switch ($status->parent_status) { + case 'announcing': + case 'ready-to-send': + if ($highest === null) $highest = ShipmentStatus::Announced; + break; + case 'to-sorting': + case 'at-sorting-centre': + case 'shipment-on-route': + case 'driver-on-route': + $highest = ShipmentStatus::EnRoute; + case 'delivered': return ShipmentStatus::Delivered; + } + } + return $highest; + } + /** * @throws SendcloudApiException */ diff --git a/classes/Modules/ShippingMethod/Model/ShipmentStatus.php b/classes/Modules/ShippingMethod/Model/ShipmentStatus.php new file mode 100644 index 00000000..de04c7b4 --- /dev/null +++ b/classes/Modules/ShippingMethod/Model/ShipmentStatus.php @@ -0,0 +1,14 @@ +Container->get('Database'); + +$shipments_sql = "SELECT CONCAT(va.id, ';', va.modul) module, vp.id, vp.tracking, vp.status + FROM versandpakete vp + JOIN versandarten va ON vp.versandart = va.type + WHERE status IN ('neu', 'versendet')"; +$shipments = $db->fetchGroup($shipments_sql); + +foreach ($shipments as $module => $vps) { + list($moduleId, $moduleName) = explode(';', $module,2); + $module = $app->erp->LoadVersandModul($moduleName, $moduleName); + + foreach ($vps as $vp) { + $status = match ($module->GetShipmentStatus($vp['tracking'])) { + ShipmentStatus::Announced => 'neu', + ShipmentStatus::EnRoute => 'versendet', + ShipmentStatus::Delivered => 'abgeschlossen', + default => null, + }; + if ($status === null || $status === $vp['status']) continue; + $db->perform('UPDATE versandpakete SET status = :status WHERE id = :id', + [':status' => $status, ':id' => $vp['id']]); + } +} diff --git a/www/lib/class.versanddienstleister.php b/www/lib/class.versanddienstleister.php index d9aa1b82..7bd7b48f 100644 --- a/www/lib/class.versanddienstleister.php +++ b/www/lib/class.versanddienstleister.php @@ -1,6 +1,6 @@ api->GetTrackingStatus($tracking); + } catch (SendcloudApiException) { + return null; + } + } + }