update 20.10.2025
This commit is contained in:
parent
8c11130b5d
commit
a939cd51ef
616 changed files with 84821 additions and 4121 deletions
|
|
@ -365,18 +365,29 @@ class ShippingService
|
|||
*/
|
||||
private function getBillingNumberForProduct(string $productCode): string
|
||||
{
|
||||
// Try to get account number from config by product code
|
||||
$accountNumber = config("dhl.account_numbers.{$productCode}");
|
||||
// Check if we're in test/sandbox mode
|
||||
$isTestMode = config('dhl.legacy.test_mode', false) || config('dhl.legacy.sandbox', false);
|
||||
|
||||
if ($accountNumber) {
|
||||
return $accountNumber;
|
||||
if ($isTestMode) {
|
||||
// Use test billing number for sandbox mode
|
||||
$testBillingNumber = '33333333330102';
|
||||
Log::info('Using DHL test billing number (sandbox mode)', [
|
||||
'product_code' => $productCode,
|
||||
'billing_number' => $testBillingNumber,
|
||||
'test_mode' => true
|
||||
]);
|
||||
return $testBillingNumber;
|
||||
}
|
||||
|
||||
// Try to get from admin settings via Setting model
|
||||
// Try to get from admin settings via Setting model first (database settings override config)
|
||||
try {
|
||||
$settingKey = 'dhl_account_' . strtolower($productCode);
|
||||
$accountNumber = \App\Models\Setting::getContentBySlug($settingKey);
|
||||
if ($accountNumber) {
|
||||
Log::info('Using DHL account number from database settings', [
|
||||
'product_code' => $productCode,
|
||||
'account_number' => $accountNumber
|
||||
]);
|
||||
return $accountNumber;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -387,6 +398,16 @@ class ShippingService
|
|||
]);
|
||||
}
|
||||
|
||||
// Try to get account number from config by product code
|
||||
$accountNumber = config("dhl.account_numbers.{$productCode}");
|
||||
if ($accountNumber) {
|
||||
Log::info('Using DHL account number from config file', [
|
||||
'product_code' => $productCode,
|
||||
'account_number' => $accountNumber
|
||||
]);
|
||||
return $accountNumber;
|
||||
}
|
||||
|
||||
// Fallback to default billing number
|
||||
$defaultBillingNumber = config('dhl.billing_number') ?: config('dhl.account_numbers.default');
|
||||
|
||||
|
|
@ -435,6 +456,35 @@ class ShippingService
|
|||
*/
|
||||
private function createShipmentRecord(array $orderData, array $payload, array $response, ?string $shipmentNumber): DhlShipment
|
||||
{
|
||||
// Extract recipient data from orderData (can be modified in modal)
|
||||
$consignee = $orderData['consignee'] ?? [];
|
||||
|
||||
// Parse name from consignee data
|
||||
$fullName = trim($consignee['name'] ?? '');
|
||||
$nameParts = explode(' ', $fullName, 2);
|
||||
$firstname = $nameParts[0] ?? '';
|
||||
$lastname = $nameParts[1] ?? '';
|
||||
|
||||
// If name is empty, try to get from separate fields
|
||||
if (empty($firstname) && empty($lastname)) {
|
||||
$firstname = $consignee['firstname'] ?? '';
|
||||
$lastname = $consignee['lastname'] ?? '';
|
||||
}
|
||||
|
||||
// Prepare complete recipient address as JSON
|
||||
$recipientData = [
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'company' => $consignee['name2'] ?? '',
|
||||
'street' => $consignee['street'] ?? '',
|
||||
'houseNumber' => $consignee['houseNumber'] ?? '',
|
||||
'postalCode' => $consignee['postalCode'] ?? '',
|
||||
'city' => $consignee['city'] ?? '',
|
||||
'country' => $consignee['country'] ?? '',
|
||||
'email' => $consignee['email'] ?? '',
|
||||
'phone' => $consignee['phone'] ?? '',
|
||||
];
|
||||
|
||||
return DhlShipment::create([
|
||||
'order_id' => $orderData['order_id'] ?? null,
|
||||
'dhl_shipment_no' => $shipmentNumber,
|
||||
|
|
@ -446,7 +496,13 @@ class ShippingService
|
|||
'status' => 'created',
|
||||
'label_format' => $payload['shipments'][0]['print']['format'],
|
||||
'label_path' => null,
|
||||
'api_response_data' => $response
|
||||
'api_response_data' => $response,
|
||||
|
||||
// Recipient data (can be modified in modal)
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'company' => $consignee['name2'] ?? '',
|
||||
'recipient' => $recipientData
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue