1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-24 19:33:07 +01:00

When creating a phone conversations try to find customer by phone number

This commit is contained in:
FreeScout 2020-09-11 00:54:58 -07:00
parent e5bd0dfe49
commit 61bb42ae3a
2 changed files with 17 additions and 0 deletions

View File

@ -675,6 +675,15 @@ class Customer extends Model
)); ));
} }
/**
* Find customer by phone number.
*/
public static function findByPhone($phone)
{
$phone = trim($phone);
return Customer::where('phones', 'LIKE', '%"'.$phone.'"%')->first();
}
/** /**
* Get customers social profiles as array. * Get customers social profiles as array.
* *

View File

@ -2500,6 +2500,14 @@ class ConversationsController extends Controller
} }
} }
// Try to find customer by phone.
if (!$customer && $request->phone) {
$customer = Customer::findByPhone($request->phone);
if ($customer) {
$customer_email = $customer->getMainEmail();
}
}
if (!$customer) { if (!$customer) {
// Create customer with passed name, email and phone // Create customer with passed name, email and phone
if (Email::sanitizeEmail($request->to_email)) { if (Email::sanitizeEmail($request->to_email)) {