From c338a8afc7e25245bb94a7ff845d7d8eba1c5b94 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 4 Oct 2025 12:55:11 +0200 Subject: [PATCH] fix: make invoices creation resistant to missing address if this still happens --- app/Repositories/Shop/InvoicePDF.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Repositories/Shop/InvoicePDF.php b/app/Repositories/Shop/InvoicePDF.php index da6e2404..b66685a6 100644 --- a/app/Repositories/Shop/InvoicePDF.php +++ b/app/Repositories/Shop/InvoicePDF.php @@ -17,12 +17,15 @@ class InvoicePDF public static function get($id) { $invoice = Invoices::getFull($id); + $customFields = []; + if ($orderRef = optional($invoice->order)->ref) { + $customFields['order number'] = $orderRef; + } + $customer = new Party([ - 'name' => $invoice->customer->name, + 'name' => optional($invoice->customer)->name ?? __('Client inconnu'), 'address' => self::makeAddress($invoice->address), - 'custom_fields' => [ - 'order number' => $invoice->order->ref, - ], + 'custom_fields' => $customFields, ]); $items = self::makeItems($invoice->order->detail); @@ -48,7 +51,17 @@ class InvoicePDF public static function makeAddress($address) { - return $address->address.'
'.$address->zipcode.' '.$address->city; + if (! $address) { + return ''; + } + + $lines = array_filter([ + $address->address ?? '', + $address->address2 ?? '', + trim(($address->zipcode ?? '').' '.($address->city ?? '')), + ]); + + return implode('
', $lines); } public static function makeItems($details)