update 20.10.2025

This commit is contained in:
Kevin Adametz 2025-10-20 17:42:08 +02:00
parent 8c11130b5d
commit a939cd51ef
616 changed files with 84821 additions and 4121 deletions

View file

@ -45,7 +45,9 @@ class DhlModalService
'availableCountries' => $this->getAvailableCountries(),
'productCodes' => $this->getAvailableProductCodes(),
'errors' => [],
'warnings' => []
'warnings' => [],
'existingShipments' => [],
'modalMode' => 'search' // 'search', 'create', 'info'
];
// If no order ID or 'new', return empty data for order selection
@ -63,26 +65,44 @@ class DhlModalService
$result['order'] = $order;
// Calculate order weight
$result['orderWeight'] = $this->calculateOrderWeight($order);
// Check for existing DHL shipments
$existingShipments = $this->getExistingShipments($order);
$result['existingShipments'] = $existingShipments;
// Process and validate shipping address
$result['shippingAddress'] = $this->processShippingAddress($order);
// Check if force_create is requested
$forceCreate = isset($data['force_create']) && $data['force_create'];
// Validate address completeness
$addressValidation = $this->validateAddress($result['shippingAddress']);
if (!$addressValidation['valid']) {
$result['errors'] = array_merge($result['errors'], $addressValidation['errors']);
// Determine modal mode based on existing shipments and force_create
if (!empty($existingShipments) && !$forceCreate) {
$result['modalMode'] = 'info';
Log::info('[DHL Modal] Order has existing shipments, showing info mode', [
'order_id' => $order->id,
'shipment_count' => count($existingShipments)
]);
} else {
$result['modalMode'] = 'create';
// Calculate order weight
$result['orderWeight'] = $this->calculateOrderWeight($order);
// Process and validate shipping address
$result['shippingAddress'] = $this->processShippingAddress($order);
// Validate address completeness
$addressValidation = $this->validateAddress($result['shippingAddress']);
if (!$addressValidation['valid']) {
$result['errors'] = array_merge($result['errors'], $addressValidation['errors']);
}
if (!empty($addressValidation['warnings'])) {
$result['warnings'] = array_merge($result['warnings'], $addressValidation['warnings']);
}
Log::info('[DHL Modal] Prepared modal data for creation', [
'order_id' => $order->id,
'weight' => $result['orderWeight'],
'address_valid' => empty($result['errors'])
]);
}
if (!empty($addressValidation['warnings'])) {
$result['warnings'] = array_merge($result['warnings'], $addressValidation['warnings']);
}
Log::info('[DHL Modal] Prepared modal data successfully', [
'order_id' => $order->id,
'weight' => $result['orderWeight'],
'address_valid' => empty($result['errors'])
]);
} catch (Exception $e) {
Log::error('[DHL Modal] Error preparing modal data', [
'order_id' => $id,
@ -106,9 +126,45 @@ class DhlModalService
return ShoppingOrder::with([
'shopping_order_items',
'shopping_user',
'dhlShipments' // Include DHL shipments
])->find($id);
}
/**
* Get existing DHL shipments for the order
*
* @param ShoppingOrder $order
* @return array
*/
private function getExistingShipments(ShoppingOrder $order): array
{
$shipments = $order->dhlShipments()
->orderBy('created_at', 'desc')
->get();
return $shipments->map(function ($shipment) {
return [
'id' => $shipment->id,
'shipment_number' => $shipment->dhl_shipment_no,
'tracking_number' => $shipment->routing_code,
'type' => $shipment->type,
'status' => $shipment->status,
'status_translated' => $shipment->getStatusTranslation(),
'type_translated' => $shipment->getTypeTranslation(),
'product_code_translated' => $shipment->getProductCodeTranslation(),
'weight' => $shipment->weight_kg,
'product_code' => $shipment->product_code,
'label_path' => $shipment->label_path,
'created_at' => $shipment->created_at->toDateTimeString(),
'tracking_status' => $shipment->tracking_status,
'tracking_status_translated' => $shipment->tracking_status ? \Acme\Dhl\Models\DhlShipment::getStatusTranslationFor($shipment->tracking_status) : null,
'last_tracked_at' => $shipment->last_tracked_at,
'can_cancel' => $shipment->canCancel(),
'is_delivered' => $shipment->isDelivered()
];
})->toArray();
}
/**
* Calculate order weight in kg
*
@ -117,7 +173,7 @@ class DhlModalService
*/
private function calculateOrderWeight(ShoppingOrder $order): float
{
return $order->weight / 100;
return $order->weight / 1000; //from grams to kg
/*
// Default fallback weight
$defaultWeight = 1.0;
@ -433,7 +489,9 @@ class DhlModalService
'zipcode' => trim($formData['shipping_zipcode'] ?? ''),
'city' => trim($formData['shipping_city'] ?? ''),
'country_id' => $country?->id,
'phone' => trim($formData['shipping_phone'] ?? '')
'country' => $country, // Store country object for DhlDataHelper
'phone' => trim($formData['shipping_phone'] ?? ''),
'email' => trim($formData['shipping_email'] ?? '') // Add email if available
];
}
}