From 1214f9b74838cd6a9d6a059d1a8b67b02bfbf6d6 Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Mon, 28 Sep 2026 11:57:30 +0300 Subject: [PATCH] Feat: Adding OrderReferenceDisplay Service that trims down order leading 0s --- .../views/checkout/confirmation.blade.php | 2 +- .../OrderCapturedNotification.php | 7 +++-- .../OrderCompletedNotification.php | 7 +++-- .../OrderDeliveredNotification.php | 7 +++-- .../OrderDispatchedNotification.php | 7 +++-- .../OrderPickupReadyNotification.php | 7 +++-- .../Notifications/OrderPlacedNotification.php | 7 +++-- .../OrderRefundedNotification.php | 7 +++-- .../OrderStatusUpdatedNotification.php | 7 +++-- src/Order/Support/OrderReferenceDisplay.php | 26 +++++++++++++++++++ 10 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 src/Order/Support/OrderReferenceDisplay.php diff --git a/resources/views/checkout/confirmation.blade.php b/resources/views/checkout/confirmation.blade.php index ae97d87..466b117 100644 --- a/resources/views/checkout/confirmation.blade.php +++ b/resources/views/checkout/confirmation.blade.php @@ -14,7 +14,7 @@
{{ __('checkout.page.confirmation_order_number') }}
-
{{ $order->reference }}
+
{{ \Modules\Core\Order\Support\OrderReferenceDisplay::resolve($order) }}
@if ($order->billingAddress?->contact_email) diff --git a/src/Order/Notifications/OrderCapturedNotification.php b/src/Order/Notifications/OrderCapturedNotification.php index 87f59ab..0d2a444 100644 --- a/src/Order/Notifications/OrderCapturedNotification.php +++ b/src/Order/Notifications/OrderCapturedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderCaptured; +use Modules\Core\Order\Support\OrderReferenceDisplay; class OrderCapturedNotification extends BaseNotification { @@ -40,10 +41,12 @@ class OrderCapturedNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Payment captured for your order :reference', ['reference' => $order->reference])) + ->subject(__('Payment captured for your order :reference', ['reference' => $reference])) ->view('core::order.notifications.captured', [ - 'reference' => $order->reference, + 'reference' => $reference, 'amount' => $this->event->transaction->amount->formatted, ]); } diff --git a/src/Order/Notifications/OrderCompletedNotification.php b/src/Order/Notifications/OrderCompletedNotification.php index 14ef7cd..7be46e0 100644 --- a/src/Order/Notifications/OrderCompletedNotification.php +++ b/src/Order/Notifications/OrderCompletedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderCompleted; +use Modules\Core\Order\Support\OrderReferenceDisplay; class OrderCompletedNotification extends BaseNotification { @@ -40,10 +41,12 @@ class OrderCompletedNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Your order :reference is complete', ['reference' => $order->reference])) + ->subject(__('Your order :reference is complete', ['reference' => $reference])) ->view('core::order.notifications.completed', [ - 'reference' => $order->reference, + 'reference' => $reference, ]); } } diff --git a/src/Order/Notifications/OrderDeliveredNotification.php b/src/Order/Notifications/OrderDeliveredNotification.php index 8c68d47..84931e8 100644 --- a/src/Order/Notifications/OrderDeliveredNotification.php +++ b/src/Order/Notifications/OrderDeliveredNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderDelivered; +use Modules\Core\Order\Support\OrderReferenceDisplay; class OrderDeliveredNotification extends BaseNotification { @@ -40,10 +41,12 @@ class OrderDeliveredNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Your order :reference has been delivered', ['reference' => $order->reference])) + ->subject(__('Your order :reference has been delivered', ['reference' => $reference])) ->view('core::order.notifications.delivered', [ - 'reference' => $order->reference, + 'reference' => $reference, ]); } } diff --git a/src/Order/Notifications/OrderDispatchedNotification.php b/src/Order/Notifications/OrderDispatchedNotification.php index 46bc43c..ac32ed8 100644 --- a/src/Order/Notifications/OrderDispatchedNotification.php +++ b/src/Order/Notifications/OrderDispatchedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderDispatched; +use Modules\Core\Order\Support\OrderReferenceDisplay; /** * Fills a real, previously-unfilled customer-communication gap — before @@ -45,10 +46,12 @@ class OrderDispatchedNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Your order :reference is on its way', ['reference' => $order->reference])) + ->subject(__('Your order :reference is on its way', ['reference' => $reference])) ->view('core::order.notifications.dispatched', [ - 'reference' => $order->reference, + 'reference' => $reference, ]); } } diff --git a/src/Order/Notifications/OrderPickupReadyNotification.php b/src/Order/Notifications/OrderPickupReadyNotification.php index 49c5844..b3b108b 100644 --- a/src/Order/Notifications/OrderPickupReadyNotification.php +++ b/src/Order/Notifications/OrderPickupReadyNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderReadyForPickup; +use Modules\Core\Order\Support\OrderReferenceDisplay; /** * "Your order is ready to collect" — listens to the specific @@ -50,10 +51,12 @@ class OrderPickupReadyNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Your order :reference is ready for pickup', ['reference' => $order->reference])) + ->subject(__('Your order :reference is ready for pickup', ['reference' => $reference])) ->view('core::order.notifications.pickup-ready', [ - 'reference' => $order->reference, + 'reference' => $reference, ]); } } diff --git a/src/Order/Notifications/OrderPlacedNotification.php b/src/Order/Notifications/OrderPlacedNotification.php index b2138c3..c9d32ba 100644 --- a/src/Order/Notifications/OrderPlacedNotification.php +++ b/src/Order/Notifications/OrderPlacedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Checkout\Events\OrderPlaced; use Modules\Core\Notification\BaseNotification; +use Modules\Core\Order\Support\OrderReferenceDisplay; /** * The order confirmation email — fires once, for every capture_mode and @@ -51,10 +52,12 @@ class OrderPlacedNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Your order :reference is confirmed', ['reference' => $order->reference])) + ->subject(__('Your order :reference is confirmed', ['reference' => $reference])) ->view('core::order.notifications.placed', [ - 'reference' => $order->reference, + 'reference' => $reference, 'total' => $order->total->formatted, 'lines' => $order->lines, ]); diff --git a/src/Order/Notifications/OrderRefundedNotification.php b/src/Order/Notifications/OrderRefundedNotification.php index b5a4d3e..d494e5f 100644 --- a/src/Order/Notifications/OrderRefundedNotification.php +++ b/src/Order/Notifications/OrderRefundedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderRefunded; +use Modules\Core\Order\Support\OrderReferenceDisplay; class OrderRefundedNotification extends BaseNotification { @@ -40,10 +41,12 @@ class OrderRefundedNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('A refund has been issued for your order :reference', ['reference' => $order->reference])) + ->subject(__('A refund has been issued for your order :reference', ['reference' => $reference])) ->view('core::order.notifications.refunded', [ - 'reference' => $order->reference, + 'reference' => $reference, 'amount' => $this->event->transaction->amount->formatted, ]); } diff --git a/src/Order/Notifications/OrderStatusUpdatedNotification.php b/src/Order/Notifications/OrderStatusUpdatedNotification.php index 099c0a0..ac7dcf9 100644 --- a/src/Order/Notifications/OrderStatusUpdatedNotification.php +++ b/src/Order/Notifications/OrderStatusUpdatedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Notification as NotificationFacade; use Modules\Core\Notification\BaseNotification; use Modules\Core\Order\Events\OrderStatusUpdated; +use Modules\Core\Order\Support\OrderReferenceDisplay; class OrderStatusUpdatedNotification extends BaseNotification { @@ -52,10 +53,12 @@ class OrderStatusUpdatedNotification extends BaseNotification { $order = $this->event->order; + $reference = OrderReferenceDisplay::resolve($order); + return (new MailMessage) - ->subject(__('Your order :reference has been updated', ['reference' => $order->reference])) + ->subject(__('Your order :reference has been updated', ['reference' => $reference])) ->view('core::order.notifications.status-updated', [ - 'reference' => $order->reference, + 'reference' => $reference, 'statusLabel' => config("lunar.orders.statuses.{$order->status}.label", $order->status), ]); } diff --git a/src/Order/Support/OrderReferenceDisplay.php b/src/Order/Support/OrderReferenceDisplay.php new file mode 100644 index 0000000..a6e4556 --- /dev/null +++ b/src/Order/Support/OrderReferenceDisplay.php @@ -0,0 +1,26 @@ +reference itself is untouched anywhere else (DB lookups, the + * order-status API, staff search) — this is purely a display helper. + */ +class OrderReferenceDisplay +{ + public static function resolve(Order $order): string + { + $reference = ltrim((string) $order->reference, '0'); + + return $reference !== '' ? $reference : '0'; + } +}