|
|
|
@@ -91,6 +91,21 @@ class CustomerController extends Controller |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
$encodedValues = json_encode($form['attribute_values'], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE); |
|
|
|
$duplicate = $this->repo()->findDuplicate((int) $form['customer_type_id'], $encodedValues); |
|
|
|
|
|
|
|
if ($duplicate !== null) { |
|
|
|
$model->form = $form; |
|
|
|
$model->errors['_duplicate'] = [ |
|
|
|
'A customer with these exact values already exists: <a href="/customers/' . (int) $duplicate['id'] . '/edit">Customer #' . (int) $duplicate['id'] . ' (' . htmlspecialchars((string) $duplicate['customer_type_name'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . ')</a>.', |
|
|
|
]; |
|
|
|
|
|
|
|
return $this->view('customers.create', [ |
|
|
|
'model' => $model, |
|
|
|
'pageTitle' => $model->title, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
$customer = new Customer(); |
|
|
|
$customer->customerTypeId = (int) $form['customer_type_id']; |
|
|
|
$customer->attributeValues = $form['attribute_values']; |
|
|
|
@@ -159,6 +174,21 @@ class CustomerController extends Controller |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
$encodedValues = json_encode($form['attribute_values'], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE); |
|
|
|
$duplicate = $this->repo()->findDuplicate((int) $form['customer_type_id'], $encodedValues, (int) $id); |
|
|
|
|
|
|
|
if ($duplicate !== null) { |
|
|
|
$model->form = $form; |
|
|
|
$model->errors['_duplicate'] = [ |
|
|
|
'These values are identical to an existing customer: <a href="/customers/' . (int) $duplicate['id'] . '/edit">Customer #' . (int) $duplicate['id'] . ' (' . htmlspecialchars((string) $duplicate['customer_type_name'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . ')</a>.', |
|
|
|
]; |
|
|
|
|
|
|
|
return $this->view('customers.edit', [ |
|
|
|
'model' => $model, |
|
|
|
'pageTitle' => $model->title, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
$customer = new Customer(); |
|
|
|
$customer->id = (int) $id; |
|
|
|
$customer->customerTypeId = (int) $form['customer_type_id']; |
|
|
|
|