// postprocess refactoring
This commit is contained in:
@@ -276,74 +276,72 @@ class AdminAddressesControllerCore extends AdminController
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
public function processSave($token)
|
||||
{
|
||||
if ($this->action == 'save')
|
||||
// Transform e-mail in id_customer for parent processing
|
||||
if (Validate::isEmail(Tools::getValue('email')))
|
||||
{
|
||||
// Transform e-mail in id_customer for parent processing
|
||||
if (Validate::isEmail(Tools::getValue('email')))
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail(Tools::getValue('email'));
|
||||
if (Validate::isLoadedObject($customer))
|
||||
$_POST['id_customer'] = $customer->id;
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('This e-mail address is not registered.');
|
||||
}
|
||||
elseif ($id_customer = Tools::getValue('id_customer'))
|
||||
{
|
||||
$customer = new Customer((int)($id_customer));
|
||||
if (Validate::isLoadedObject($customer))
|
||||
$_POST['id_customer'] = $customer->id;
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Unknown customer');
|
||||
}
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail(Tools::getValue('email'));
|
||||
if (Validate::isLoadedObject($customer))
|
||||
$_POST['id_customer'] = $customer->id;
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('This e-mail address is not registered.');
|
||||
}
|
||||
elseif ($id_customer = Tools::getValue('id_customer'))
|
||||
{
|
||||
$customer = new Customer((int)($id_customer));
|
||||
if (Validate::isLoadedObject($customer))
|
||||
$_POST['id_customer'] = $customer->id;
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Unknown customer');
|
||||
if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) AND !Tools::getValue('dni'))
|
||||
$this->_errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
|
||||
|
||||
/* If the selected country does not contain states */
|
||||
$id_state = (int)(Tools::getValue('id_state'));
|
||||
if ($id_country = Tools::getValue('id_country') AND $country = new Country((int)($id_country)) AND !(int)($country->contains_states) AND $id_state)
|
||||
$this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
|
||||
|
||||
/* If the selected country contains states, then a state have to be selected */
|
||||
if ((int)($country->contains_states) AND !$id_state)
|
||||
$this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
|
||||
|
||||
/* Check zip code */
|
||||
if ($country->need_zip_code)
|
||||
{
|
||||
$zip_code_format = $country->zip_code_format;
|
||||
if (($postcode = Tools::getValue('postcode')) AND $zip_code_format)
|
||||
{
|
||||
$zip_regexp = '/^'.$zip_code_format.'$/ui';
|
||||
$zip_regexp = str_replace(' ', '( |)', $zip_regexp);
|
||||
$zip_regexp = str_replace('-', '(-|)', $zip_regexp);
|
||||
$zip_regexp = str_replace('N', '[0-9]', $zip_regexp);
|
||||
$zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp);
|
||||
$zip_regexp = str_replace('C', $country->iso_code, $zip_regexp);
|
||||
if (!preg_match($zip_regexp, $postcode))
|
||||
$this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
|
||||
}
|
||||
elseif ($zip_code_format)
|
||||
$this->_errors[] = Tools::displayError('Postcode required.');
|
||||
elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode))
|
||||
$this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
|
||||
}
|
||||
|
||||
/* If this address come from order's edition and is the same as the other one (invoice or delivery one)
|
||||
** we delete its id_address to force the creation of a new one */
|
||||
if ((int)(Tools::getValue('id_order')))
|
||||
{
|
||||
$this->_redirect = false;
|
||||
if (isset($_POST['address_type']))
|
||||
$_POST['id_address'] = '';
|
||||
}
|
||||
}
|
||||
if (!sizeof($this->_errors))
|
||||
parent::postProcess();
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Unknown customer');
|
||||
if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) AND !Tools::getValue('dni'))
|
||||
$this->_errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
|
||||
|
||||
/* If the selected country does not contain states */
|
||||
$id_state = (int)(Tools::getValue('id_state'));
|
||||
if ($id_country = Tools::getValue('id_country') AND $country = new Country((int)($id_country)) AND !(int)($country->contains_states) AND $id_state)
|
||||
$this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
|
||||
|
||||
/* If the selected country contains states, then a state have to be selected */
|
||||
if ((int)($country->contains_states) AND !$id_state)
|
||||
$this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
|
||||
|
||||
/* Check zip code */
|
||||
if ($country->need_zip_code)
|
||||
{
|
||||
$zip_code_format = $country->zip_code_format;
|
||||
if (($postcode = Tools::getValue('postcode')) AND $zip_code_format)
|
||||
{
|
||||
$zip_regexp = '/^'.$zip_code_format.'$/ui';
|
||||
$zip_regexp = str_replace(' ', '( |)', $zip_regexp);
|
||||
$zip_regexp = str_replace('-', '(-|)', $zip_regexp);
|
||||
$zip_regexp = str_replace('N', '[0-9]', $zip_regexp);
|
||||
$zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp);
|
||||
$zip_regexp = str_replace('C', $country->iso_code, $zip_regexp);
|
||||
if (!preg_match($zip_regexp, $postcode))
|
||||
$this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
|
||||
}
|
||||
elseif ($zip_code_format)
|
||||
$this->_errors[] = Tools::displayError('Postcode required.');
|
||||
elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode))
|
||||
$this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
|
||||
}
|
||||
|
||||
/* If this address come from order's edition and is the same as the other one (invoice or delivery one)
|
||||
** we delete its id_address to force the creation of a new one */
|
||||
if ((int)(Tools::getValue('id_order')))
|
||||
{
|
||||
$this->_redirect = false;
|
||||
if (isset($_POST['address_type']))
|
||||
$_POST['id_address'] = '';
|
||||
}
|
||||
|
||||
if (empty($this->_errors))
|
||||
parent::processSave($token);
|
||||
|
||||
/* Reassignation of the order's new (invoice or delivery) address */
|
||||
$address_type = ((int)(Tools::getValue('address_type')) == 2 ? 'invoice' : ((int)(Tools::getValue('address_type')) == 1 ? 'delivery' : ''));
|
||||
|
||||
@@ -51,7 +51,7 @@ class AdminGroupsController extends AdminController
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 80, 'filter_key' => 'b!name'),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 'auto', 'filter_key' => 'b!name'),
|
||||
'reduction' => array('title' => $this->l('Discount'), 'width' => 50, 'align' => 'right'),
|
||||
'nb' => array('title' => $this->l('Members'), 'width' => 25, 'align' => 'center'),
|
||||
'date_add' => array('title' => $this->l('Creation date'), 'width' => 60, 'type' => 'date', 'align' => 'right'));
|
||||
@@ -76,14 +76,14 @@ class AdminGroupsController extends AdminController
|
||||
|
||||
$this->tpl_view_vars = array(
|
||||
'group' => $group,
|
||||
'customerList' => $this->initCustomersList($group),
|
||||
'customerList' => $this->renderCustomersList($group),
|
||||
'categorieReductions' => $this->formatCategoryDiscountList($group->id)
|
||||
);
|
||||
|
||||
return parent::renderView();
|
||||
}
|
||||
|
||||
protected function initCustomersList($group)
|
||||
protected function renderCustomersList($group)
|
||||
{
|
||||
$genders = array(0 => $this->l('?'));
|
||||
foreach (Gender::getGenders() as $gender)
|
||||
@@ -275,26 +275,16 @@ class AdminGroupsController extends AdminController
|
||||
return array('unauth_modules' => $unauth_modules, 'auth_modules' => $auth_modules);
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
public function processSave($token)
|
||||
{
|
||||
if (Tools::isSubmit('submitAddgroup'))
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
{
|
||||
if (!$this->validateDiscount(Tools::getValue('reduction')))
|
||||
$this->_errors[] = Tools::displayError('Discount value is incorrect (must be a percentage)');
|
||||
else
|
||||
{
|
||||
$this->updateCategoryReduction();
|
||||
$this->updateRestrictions();
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||
}
|
||||
if (!$this->validateDiscount(Tools::getValue('reduction')))
|
||||
$this->_errors[] = Tools::displayError('Discount value is incorrect (must be a percentage)');
|
||||
else
|
||||
parent::postProcess();
|
||||
{
|
||||
$this->updateCategoryReduction();
|
||||
$this->updateRestrictions();
|
||||
parent::processSave($token);
|
||||
}
|
||||
}
|
||||
|
||||
protected function validateDiscount($reduction)
|
||||
|
||||
Reference in New Issue
Block a user