From 1061df8c8b6ccbe6fa67629bc425a2fbf88208eb Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 13 Nov 2024 13:07:28 -0800 Subject: [PATCH] fix user checkout license category email check --- app/Listeners/CheckoutableListener.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 5b740e3f42..c5499784b7 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -77,7 +77,7 @@ class CheckoutableListener */ if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || - (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) { + $this->checkoutableShouldSendEmail($event)) { Log::info('Sending checkout email, Locale: ' . ($event->checkedOutTo->locale ?? 'default')); if (!empty($notifiable)) { Mail::to($notifiable)->cc($ccEmails)->send($mailable); @@ -146,7 +146,6 @@ class CheckoutableListener $ccEmails = array_filter($adminCcEmailsArray); $mailable = $this->getCheckinMailType($event); $notifiable = $this->getNotifiables($event); - if (!$event->checkedOutTo->locale){ $mailable->locale($event->checkedOutTo->locale); } @@ -159,7 +158,7 @@ class CheckoutableListener * 3. The item should send an email at check-in/check-out */ if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || - (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) { + $this->checkoutableShouldSendEmail($event)) { Log::info('Sending checkin email, Locale: ' . ($event->checkedOutTo->locale ?? 'default')); if (!empty($notifiable)) { Mail::to($notifiable)->cc($ccEmails)->send($mailable); @@ -338,4 +337,12 @@ class CheckoutableListener { return Setting::getSettings() && Setting::getSettings()->webhook_endpoint; } + + private function checkoutableShouldSendEmail($event): bool + { + if($event->checkoutable instanceof LicenseSeat){ + return $event->checkoutable->license->checkin_email(); + } + return (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email()); + } }