From 6c34a5c52c8e5391dab246c69a41ad118cfb0cc5 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 23 Oct 2024 14:54:21 -0700 Subject: [PATCH] conditionally check cc emails, initiate variables --- app/Listeners/CheckoutableListener.php | 32 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 99faa281d7..02f8081e6b 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -52,10 +52,17 @@ class CheckoutableListener */ $settings = Setting::getSettings(); $acceptance = $this->getCheckoutAcceptance($event); - $emailsArray = $settings->alert_email; - $adminCcEmail = $settings->admin_cc_email; - $alertsEmailsArray = array_map('trim', explode(',', $emailsArray)); - $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); + $alertsEmailsArray = []; + $adminCcEmailsArray = []; + + if($settings->alert_email !== '') { + $emailsArray = $settings->alert_email; + $alertsEmailsArray = array_map('trim', explode(',', $emailsArray)); + } + if($settings->admin_cc_email !== '') { + $adminCcEmail = $settings->admin_cc_email; + $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); + } $ccEmails = array_merge($alertsEmailsArray, $adminCcEmailsArray); $notifiable = $event->checkedOutTo; $mailable = $this->getCheckoutMailType($event, $acceptance); @@ -118,13 +125,22 @@ class CheckoutableListener } } $settings = Setting::getSettings(); - $emailsArray = $settings->alert_email; - $adminCcEmail = $settings->admin_cc_email; - $alertsEmailsArray = array_map('trim', explode(',', $emailsArray)); - $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); + $alertsEmailsArray = []; + $adminCcEmailsArray = []; + + if($settings->alert_email !== '') { + $emailsArray = $settings->alert_email; + $alertsEmailsArray = array_map('trim', explode(',', $emailsArray)); + } + if($settings->admin_cc_email !== '') { + $adminCcEmail = $settings->admin_cc_email; + $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); + } $ccEmails = array_merge($alertsEmailsArray, $adminCcEmailsArray); + $notifiable = $event->checkedOutTo; $mailable = $this->getCheckinMailType($event); + // Send email notifications try { if (!$event->checkedOutTo->locale){