Skip to content

Commit 27cef80

Browse files
Do not allow to merge customer with himself - closes #4986
1 parent 76467c1 commit 27cef80

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/Customer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,10 @@ public static function getPhotoUrlByFileName($file_name)
12921292
*/
12931293
public function mergeWith(Customer $customer2)
12941294
{
1295+
if ($this->id == $customer2->id) {
1296+
return false;
1297+
}
1298+
12951299
$user = auth()->user();
12961300

12971301
$customer2->conversations()->update(['customer_id' => $this->id]);
@@ -1341,6 +1345,8 @@ public function mergeWith(Customer $customer2)
13411345
\Eventy::action('customer.merged', $this, $customer2, $user);
13421346

13431347
$customer2->delete();
1348+
1349+
return true;
13441350
}
13451351

13461352
public static function mergeTypeValueLists($list1, $list2)

app/Http/Controllers/CustomersController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,10 @@ public function merge(Request $request, $id)
498498
public function mergeSave(Request $request, $id)
499499
{
500500
$request->validate([
501-
'customer2_id' => 'required|exists:customers,id',
501+
'customer2_id' => 'required|exists:customers,id|not_in:'.$id,
502502
//'keep_attributes' => 'array'
503+
], [], [
504+
'customer2_id' => __('Merge With')
503505
]);
504506

505507
$customer = Customer::findOrFail($id);

0 commit comments

Comments
 (0)