From 36ace2bb7edeffb1d8954096ababdd02ba1b8545 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Wed, 24 Jul 2019 22:51:16 -0700 Subject: [PATCH] If customer without name show first part of email in profile --- app/Customer.php | 17 ++++++++++++----- .../views/customers/profile_snippet.blade.php | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Customer.php b/app/Customer.php index 46877495..88cf27d9 100644 --- a/app/Customer.php +++ b/app/Customer.php @@ -477,7 +477,7 @@ class Customer extends Model * * @return string */ - public function getFullName($email_if_empty = false) + public function getFullName($email_if_empty = false, $first_part_from_email = false) { if ($this->first_name && $this->last_name) { return $this->first_name.' '.$this->last_name; @@ -486,7 +486,12 @@ class Customer extends Model } elseif (!$this->first_name && $this->last_name) { return $this->last_name; } elseif ($email_if_empty) { - return $this->getMainEmail(); + $email = $this->getMainEmail(); + if ($first_part_from_email) { + return $this->getNameFromEmail($email); + } else { + return $email; + } } return ''; @@ -513,11 +518,13 @@ class Customer extends Model * * @return string */ - public function getNameFromEmail() + public function getNameFromEmail($email = '') { - $email = $this->emails()->first(); + if (!$email) { + $email = optional($this->emails_cached()->first())->email; + } if ($email) { - return explode('@', $email->email)[0]; + return explode('@', $email)[0]; } else { return ''; } diff --git a/resources/views/customers/profile_snippet.blade.php b/resources/views/customers/profile_snippet.blade.php index 73005d5f..4060a0aa 100644 --- a/resources/views/customers/profile_snippet.blade.php +++ b/resources/views/customers/profile_snippet.blade.php @@ -3,8 +3,8 @@
- @if ($customer->getFullName(true)) - {{ $customer->getFullName(true) }} + @if ($customer->getFullName(true, true)) + {{ $customer->getFullName(true, true) }} @endif {{-- todo: display full customer info --}}