diff --git a/classes/AdminController.php b/classes/AdminController.php
index c55b6d4bb..adb7a32b2 100644
--- a/classes/AdminController.php
+++ b/classes/AdminController.php
@@ -610,7 +610,10 @@ class AdminControllerCore extends Controller
public function processSave($token)
{
if ($this->id_object)
+ {
+ $this->object = $this->loadObject();
return $this->processUpdate($token);
+ }
else
return $this->processAdd($token);
}
@@ -673,7 +676,7 @@ class AdminControllerCore extends Controller
/* Checking fields validity */
$this->validateRules();
- if (count($this->errors) <= 0)
+ if (empty($this->errors))
{
$id = (int)Tools::getValue($this->identifier);
@@ -745,7 +748,7 @@ class AdminControllerCore extends Controller
}
}
$this->errors = array_unique($this->errors);
- if (count($this->errors) > 0)
+ if (!empty($this->errors))
return;
if (isset($object))
return $object;
diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php
index 088560de6..454e482fb 100644
--- a/controllers/admin/AdminCustomersController.php
+++ b/controllers/admin/AdminCustomersController.php
@@ -718,46 +718,49 @@ class AdminCustomersControllerCore extends AdminController
parent::processDelete($token);
}
- public function processSave($token)
+ public function processAdd($token)
{
// Check that the new email is not already in use
- // Case add
- if (!$this->id_object)
+ $customer_email = strval(Tools::getValue('email'));
+ $customer = new Customer();
+ if (Validate::isEmail($customer_email))
+ $customer->getByEmail($customer_email);
+ if ($customer->id)
+ $this->errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
+ else
+ return parent::processAdd($token);
+
+ }
+
+ public function processUpdate($token)
+ {
+ if (Validate::isLoadedObject($this->object))
{
$customer_email = strval(Tools::getValue('email'));
- $customer = new Customer();
- if (Validate::isEmail($customer_email))
- $customer->getByEmail($customer_email);
- if ($customer->id)
- $this->errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
- }
- // Case update
- else
- {
- $object = new $this->className($this->id_object);
- if (Validate::isLoadedObject($object))
+
+ // check if e-mail already used
+ if ($customer_email != $this->object->email)
{
- $customer_email = strval(Tools::getValue('email'));
-
- // check if e-mail already used
- if ($customer_email != $object->email)
- {
- $customer = new Customer();
- $customer->getByEmail($customer_email);
- if ($customer->id)
- $this->errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
- }
+ $customer = new Customer();
+ $customer->getByEmail($customer_email);
+ if ($customer->id)
+ $this->errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
}
- else
- $this->errors[] = Tools::displayError('An error occurred while loading object.').'
- '.$this->table.' '.Tools::displayError('(cannot load object)');
- }
+ return parent::processUpdate($token);
+ }
+ else
+ $this->errors[] = Tools::displayError('An error occurred while loading object.').'
+ '.$this->table.' '.Tools::displayError('(cannot load object)');
+ }
+
+ public function processSave($token)
+ {
// Check that default group is selected
if (!is_array(Tools::getValue('groupBox')) || !in_array(Tools::getValue('id_default_group'), Tools::getValue('groupBox')))
$this->errors[] = Tools::displayError('Default customer group must be selected in group box.');
- parent::processSave($token);
+ return parent::processSave($token);
}
public function afterDelete($object, $oldId)