From 3fa5976315ef6cff5c8ed1e4bd414af5d162ff90 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Date: Tue, 22 Jan 2019 16:02:08 -0600 Subject: [PATCH] Language of mail doesn't show as intended by the settings. [ch87] (#6619) * Fixes #5554. Language of mail doesn't show as intended by the settings. --- app/Listeners/CheckoutableListener.php | 30 ++++++++++++++----- app/Models/User.php | 7 ++++- .../CheckinLicenseSeatNotification.php | 1 - 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 43eedf54d8..c209dac612 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -40,10 +40,17 @@ class CheckoutableListener */ $acceptance = $this->getCheckoutAcceptance($event); - Notification::send( - $this->getNotifiables($event), - $this->getCheckoutNotification($event, $acceptance) - ); + if(!$event->checkedOutTo->locale){ + Notification::locale(Setting::getSettings()->locale)->send( + $this->getNotifiables($event), + $this->getCheckoutNotification($event, $acceptance) + ); + } else { + Notification::send( + $this->getNotifiables($event), + $this->getCheckoutNotification($event, $acceptance) + ); + } } /** @@ -60,10 +67,17 @@ class CheckoutableListener /** * Send the appropriate notification */ - Notification::send( - $this->getNotifiables($event), - $this->getCheckinNotification($event) - ); + if(!$event->checkedOutTo->locale){ + Notification::locale(Setting::getSettings()->locale)->send( + $this->getNotifiables($event), + $this->getCheckinNotification($event) + ); + } else { + Notification::send( + $this->getNotifiables($event), + $this->getCheckinNotification($event) + ); + } } /** diff --git a/app/Models/User.php b/app/Models/User.php index a390686e87..2594bed155 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -15,11 +15,12 @@ use Illuminate\Database\Eloquent\SoftDeletes; use App\Http\Traits\UniqueUndeletedTrait; use Illuminate\Notifications\Notifiable; use Laravel\Passport\HasApiTokens; +use Illuminate\Contracts\Translation\HasLocalePreference; use DB; -class User extends SnipeModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract +class User extends SnipeModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, HasLocalePreference { protected $presenter = 'App\Presenters\UserPresenter'; use SoftDeletes, ValidatingTrait; @@ -643,4 +644,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo { return $query->leftJoin('departments as departments_users', 'users.department_id', '=', 'departments_users.id')->orderBy('departments_users.name', $order); } + + public function preferredLocale(){ + return $this->locale; + } } diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index 69554d493b..6851055ce0 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -96,7 +96,6 @@ class CheckinLicenseSeatNotification extends Notification */ public function toMail($notifiable) { - return (new MailMessage)->markdown('notifications.markdown.checkin-license', [ 'item' => $this->item,