20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Log;
|
|||
|
||||
/**
|
||||
* Job to create DHL return labels asynchronously
|
||||
*
|
||||
*
|
||||
* This job handles the creation of DHL return labels in the background,
|
||||
* preventing API timeouts and improving user experience.
|
||||
*/
|
||||
|
|
@ -50,9 +50,6 @@ class CreateReturnLabelJob implements ShouldQueue
|
|||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param DhlShipment $originalShipment
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(DhlShipment $originalShipment, array $options = [])
|
||||
{
|
||||
|
|
@ -80,7 +77,7 @@ class CreateReturnLabelJob implements ShouldQueue
|
|||
]);
|
||||
|
||||
// Get DHL configuration
|
||||
$settingController = new SettingController();
|
||||
$settingController = new SettingController;
|
||||
$dhlConfig = $settingController->getDhlConfig();
|
||||
|
||||
// Initialize DHL client
|
||||
|
|
@ -136,15 +133,22 @@ class CreateReturnLabelJob implements ShouldQueue
|
|||
$order = $this->originalShipment->shoppingOrder;
|
||||
$recipient = $this->originalShipment->recipient ?? [];
|
||||
|
||||
return [
|
||||
'order_id' => $order->id,
|
||||
'original_shipment_id' => $this->originalShipment->id,
|
||||
'weight_kg' => $this->originalShipment->weight_kg,
|
||||
'label_format' => $this->originalShipment->label_format ?? 'PDF',
|
||||
// Check if this is a Packstation delivery - use billing address as return sender
|
||||
$hasPostNumber = ! empty($recipient['postnumber'] ?? $recipient['postNumber'] ?? '');
|
||||
|
||||
// Shipper: Customer sends back to us (swap addresses)
|
||||
'shipper' => [
|
||||
'name' => trim(($recipient['firstname'] ?? '') . ' ' . ($recipient['lastname'] ?? '')),
|
||||
if ($hasPostNumber) {
|
||||
Log::info('[DHL Queue] Packstation detected - using billing address for return sender', [
|
||||
'shipment_id' => $this->originalShipment->id,
|
||||
'order_id' => $order->id,
|
||||
]);
|
||||
|
||||
// Load billing address from order
|
||||
$shippingUser = $order->shopping_user;
|
||||
$shipperAddress = $this->getBillingAddressForReturn($shippingUser, $recipient);
|
||||
} else {
|
||||
// Use original recipient address (normal delivery)
|
||||
$shipperAddress = [
|
||||
'name' => trim(($recipient['firstname'] ?? '').' '.($recipient['lastname'] ?? '')),
|
||||
'name2' => $recipient['company'] ?? '',
|
||||
'street' => $recipient['street'] ?? '',
|
||||
'houseNumber' => $recipient['houseNumber'] ?? '',
|
||||
|
|
@ -153,7 +157,17 @@ class CreateReturnLabelJob implements ShouldQueue
|
|||
'country' => $recipient['country'] ?? 'DEU',
|
||||
'email' => $recipient['email'] ?? '',
|
||||
'phone' => $recipient['phone'] ?? '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'order_id' => $order->id,
|
||||
'original_shipment_id' => $this->originalShipment->id,
|
||||
'weight_kg' => $this->originalShipment->weight_kg,
|
||||
'label_format' => $this->originalShipment->label_format ?? 'PDF',
|
||||
|
||||
// Shipper: Customer sends back to us (using billing address for Packstation)
|
||||
'shipper' => $shipperAddress,
|
||||
|
||||
// Consignee: Our warehouse (from settings)
|
||||
'consignee' => [
|
||||
|
|
@ -170,10 +184,56 @@ class CreateReturnLabelJob implements ShouldQueue
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get billing address for return label (used when original delivery was to Packstation)
|
||||
*/
|
||||
private function getBillingAddressForReturn($shippingUser, array $recipient): array
|
||||
{
|
||||
if (! $shippingUser) {
|
||||
Log::warning('[DHL Queue] No shipping user found, using recipient data', [
|
||||
'recipient' => $recipient,
|
||||
]);
|
||||
|
||||
// Fallback: use recipient data but without Packstation fields
|
||||
return [
|
||||
'name' => trim(($recipient['firstname'] ?? '').' '.($recipient['lastname'] ?? '')),
|
||||
'name2' => $recipient['company'] ?? '',
|
||||
'street' => 'Adresse fehlt',
|
||||
'houseNumber' => '',
|
||||
'postalCode' => $recipient['postalCode'] ?? '',
|
||||
'city' => $recipient['city'] ?? '',
|
||||
'country' => $recipient['country'] ?? 'DEU',
|
||||
'email' => $recipient['email'] ?? '',
|
||||
'phone' => $recipient['phone'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
// Parse billing address to extract street and house number
|
||||
$billingAddress = trim($shippingUser->billing_address ?? '');
|
||||
$street = $billingAddress;
|
||||
$houseNumber = '';
|
||||
|
||||
// Try to extract house number from address
|
||||
if (preg_match('/^(.+?)\s+(\d+[a-zA-Z]?[-\/\d]*)$/u', $billingAddress, $matches)) {
|
||||
$street = trim($matches[1]);
|
||||
$houseNumber = trim($matches[2]);
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => trim(($shippingUser->billing_firstname ?? '').' '.($shippingUser->billing_lastname ?? '')),
|
||||
'name2' => $shippingUser->billing_company ?? '',
|
||||
'street' => $street,
|
||||
'houseNumber' => $houseNumber,
|
||||
'postalCode' => $shippingUser->billing_zipcode ?? '',
|
||||
'city' => $shippingUser->billing_city ?? '',
|
||||
'country' => $shippingUser->billing_country?->code ?? 'DEU',
|
||||
'email' => $shippingUser->billing_email ?? '',
|
||||
'phone' => $shippingUser->billing_phone ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a job failure.
|
||||
*
|
||||
* @param Exception $exception
|
||||
*/
|
||||
public function failed(Exception $exception): void
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue