[*] BO : #PSCFV-3831 : check each field which are required in databases
This commit is contained in:
@@ -1058,6 +1058,28 @@ abstract class ObjectModelCore
|
|||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validateFieldsRequiredDatabase($htmlentities = true)
|
||||||
|
{
|
||||||
|
$errors = array();
|
||||||
|
$required_fields = (isset(self::$fieldsRequiredDatabase[get_class($this)])) ? self::$fieldsRequiredDatabase[get_class($this)] : array();
|
||||||
|
|
||||||
|
foreach ($this->def['fields'] as $field => $data)
|
||||||
|
{
|
||||||
|
if (!in_array($field, $required_fields))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!method_exists('Validate', $data['validate']))
|
||||||
|
throw new PrestaShopException('Validation function not found. '.$data['validate']);
|
||||||
|
|
||||||
|
$value = Tools::getValue($field);
|
||||||
|
|
||||||
|
if (empty($value))
|
||||||
|
$errors[] = sprintf(Tools::displayError('The field %s is required.'), self::displayFieldName($field, get_class($this), $htmlentities));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFieldsRequiredDatabase($all = false)
|
public function getFieldsRequiredDatabase($all = false)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->executeS('
|
return Db::getInstance()->executeS('
|
||||||
|
|||||||
@@ -370,6 +370,10 @@ class AdminAddressesControllerCore extends AdminController
|
|||||||
$_POST['id_address'] = '';
|
$_POST['id_address'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the requires fields which are settings in the BO
|
||||||
|
$address = new Address();
|
||||||
|
$this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
|
||||||
|
|
||||||
if (empty($this->errors))
|
if (empty($this->errors))
|
||||||
return parent::processSave();
|
return parent::processSave();
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -769,6 +769,10 @@ class AdminCustomersControllerCore extends AdminController
|
|||||||
if (!is_array(Tools::getValue('groupBox')) || !in_array(Tools::getValue('id_default_group'), Tools::getValue('groupBox')))
|
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.');
|
$this->errors[] = Tools::displayError('Default customer group must be selected in group box.');
|
||||||
|
|
||||||
|
// Check the requires fields which are settings in the BO
|
||||||
|
$customer = new Customer();
|
||||||
|
$this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase());
|
||||||
|
|
||||||
return parent::processSave();
|
return parent::processSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -182,6 +182,9 @@ class AddressControllerCore extends FrontController
|
|||||||
AND deleted = 0') > 0)
|
AND deleted = 0') > 0)
|
||||||
$this->errors[] = sprintf(Tools::displayError('The alias "%s" is already used, please chose another one.'), Tools::safeOutput($_POST['alias']));
|
$this->errors[] = sprintf(Tools::displayError('The alias "%s" is already used, please chose another one.'), Tools::safeOutput($_POST['alias']));
|
||||||
|
|
||||||
|
// Check the requires fields which are settings in the BO
|
||||||
|
$this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
|
||||||
|
|
||||||
// Don't continue this process if we have errors !
|
// Don't continue this process if we have errors !
|
||||||
if ($this->errors && !$this->ajax)
|
if ($this->errors && !$this->ajax)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -394,6 +394,10 @@ class AuthControllerCore extends FrontController
|
|||||||
if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile') && Configuration::get('PS_REGISTRATION_PROCESS_TYPE'))
|
if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile') && Configuration::get('PS_REGISTRATION_PROCESS_TYPE'))
|
||||||
$this->errors[] = Tools::displayError('You must register at least one phone number');
|
$this->errors[] = Tools::displayError('You must register at least one phone number');
|
||||||
$this->errors = array_unique(array_merge($this->errors, $customer->validateController()));
|
$this->errors = array_unique(array_merge($this->errors, $customer->validateController()));
|
||||||
|
|
||||||
|
// Check the requires fields which are settings in the BO
|
||||||
|
$this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase());
|
||||||
|
|
||||||
if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount'))
|
if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount'))
|
||||||
{
|
{
|
||||||
if (!count($this->errors))
|
if (!count($this->errors))
|
||||||
|
|||||||
Reference in New Issue
Block a user