本文整理汇总了PHP中Address::validateFieldsRequiredDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::validateFieldsRequiredDatabase方法的具体用法?PHP Address::validateFieldsRequiredDatabase怎么用?PHP Address::validateFieldsRequiredDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::validateFieldsRequiredDatabase方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processSave
public function processSave()
{
if (Tools::getValue('submitFormAjax')) {
$this->redirect_after = false;
}
// Transform e-mail in id_customer for parent processing
if (Validate::isEmail(Tools::getValue('email'))) {
$customer = new Customer();
$customer->getByEmail(Tools::getValue('email'), null, false);
if (Validate::isLoadedObject($customer)) {
$_POST['id_customer'] = $customer->id;
} else {
$this->errors[] = Tools::displayError('This email address is not registered.');
}
} else {
if ($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');
}
} else {
$this->errors[] = Tools::displayError('Unknown customer');
}
}
if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) && !Tools::getValue('dni')) {
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
}
/* If the selected country does not contain states */
$id_state = (int) Tools::getValue('id_state');
$id_country = (int) Tools::getValue('id_country');
$country = new Country((int) $id_country);
if ($country && !(int) $country->contains_states && $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 && !$id_state) {
$this->errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
}
$postcode = Tools::getValue('postcode');
/* Check zip code format */
if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
$this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
} elseif (empty($postcode) && $country->need_zip_code) {
$this->errors[] = Tools::displayError('A Zip/postal code is required.');
} elseif ($postcode && !Validate::isPostCode($postcode)) {
$this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
}
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
$this->errors[] = Tools::displayError('You must register at least one phone number.');
}
/* 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'] = '';
}
}
// 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)) {
return parent::processSave();
} else {
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';
}
/* 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' : '');
if ($this->action == 'save' && ($id_order = (int) Tools::getValue('id_order')) && !count($this->errors) && !empty($address_type)) {
if (!Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'orders SET `id_address_' . $address_type . '` = ' . Db::getInstance()->Insert_ID() . ' WHERE `id_order` = ' . $id_order)) {
$this->errors[] = Tools::displayError('An error occurred while linking this address to its order.');
} else {
Tools::redirectAdmin(Tools::getValue('back') . '&conf=4');
}
}
}
示例2: processSubmitAddress
/**
* Process changes on an address
*/
protected function processSubmitAddress()
{
$address = new Address();
$this->errors = $address->validateController();
$address->id_customer = (int) $this->context->customer->id;
// Check page token
if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
$this->errors[] = Tools::displayError('Invalid token.');
}
// Check phone
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
$this->errors[] = Tools::displayError('You must register at least one phone number.');
}
if ($address->id_country) {
// Check country
if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
throw new PrestaShopException('Country cannot be loaded with address->id_country');
}
if ((int) $country->contains_states && !(int) $address->id_state) {
$this->errors[] = Tools::displayError('This country requires you to chose a State.');
}
// US customer: normalize the address
if ($address->id_country == Country::getByIso('US') && Configuration::get('PS_TAASC')) {
include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
$normalize = new AddressStandardizationSolution();
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
$postcode = Tools::getValue('postcode');
/* Check zip code format */
if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
$this->errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
} elseif (empty($postcode) && $country->need_zip_code) {
$this->errors[] = Tools::displayError('A Zip / Postal code is required.');
} elseif ($postcode && !Validate::isPostCode($postcode)) {
$this->errors[] = Tools::displayError('The Zip / Postal code is invalid.');
}
// Check country DNI nox fix
/*if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
else if (!$country->isNeedDni())
$address->dni = null;*/
if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
} elseif (!$country->need_identification_number) {
${$addresses_type}->dni = null;
}
}
// Check if the alias exists
if (!$this->context->customer->is_guest && !empty($_POST['alias']) && (int) $this->context->customer->id > 0) {
$id_address = Tools::getValue('id_address');
if (Configuration::get('PS_ORDER_PROCESS_TYPE') && (int) Tools::getValue('opc_id_address_' . Tools::getValue('type')) > 0) {
$id_address = Tools::getValue('opc_id_address_' . Tools::getValue('type'));
}
if (Db::getInstance()->getValue('
SELECT count(*)
FROM ' . _DB_PREFIX_ . 'address
WHERE `alias` = \'' . pSql($_POST['alias']) . '\'
AND id_address != ' . (int) $id_address . '
AND id_customer = ' . (int) $this->context->customer->id . '
AND deleted = 0') > 0) {
$this->errors[] = sprintf(Tools::displayError('The alias "%s" has already been used. Please select 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 !
if ($this->errors && !$this->ajax) {
return;
}
// If we edit this address, delete old address and create a new one
if (Validate::isLoadedObject($this->_address)) {
if (Validate::isLoadedObject($country) && !$country->contains_states) {
$address->id_state = 0;
}
$address_old = $this->_address;
if (Customer::customerHasAddress($this->context->customer->id, (int) $address_old->id)) {
if ($address_old->isUsed()) {
$address_old->delete();
} else {
$address->id = (int) $address_old->id;
$address->date_add = $address_old->date_add;
}
}
}
if ($this->ajax && Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$this->errors = array_unique(array_merge($this->errors, $address->validateController()));
if (count($this->errors)) {
$return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors);
die(Tools::jsonEncode($return));
}
}
// Save address
if ($result = $address->save()) {
// Update id address of the current cart if necessary
if (isset($address_old) && $address_old->isUsed()) {
$this->context->cart->updateAddressId($address_old->id, $address->id);
//.........这里部分代码省略.........
示例3: processSubmitAddress
/**
* Process changes on an address
*/
protected function processSubmitAddress()
{
$address = new Address();
$this->errors = $address->validateController();
$address->id_customer = (int) $this->context->customer->id;
// Check page token
if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
$this->errors[] = Tools::displayError('Invalid token.');
}
// Check phone
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
$this->errors[] = Tools::displayError('You must register at least one phone number.');
}
if ($address->id_country) {
// Check country
if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
throw new PrestaShopException('Country cannot be loaded with address->id_country');
}
// if ((int)$country->contains_states && !(int)$address->id_state)
// $this->errors[] = Tools::displayError('This country requires you to chose a State.');
if (!$country->active) {
$this->errors[] = Tools::displayError('This country is not active.');
}
// Check country DNI
if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
} elseif (!$country->isNeedDni()) {
$address->dni = null;
}
}
// Check if the alias exists
if (!$this->context->customer->is_guest && !empty($_POST['alias']) && (int) $this->context->customer->id > 0) {
$id_address = Tools::getValue('id_address');
if (Configuration::get('PS_ORDER_PROCESS_TYPE') && (int) Tools::getValue('opc_id_address_' . Tools::getValue('type')) > 0) {
$id_address = Tools::getValue('opc_id_address_' . Tools::getValue('type'));
}
if (Address::aliasExist(Tools::getValue('alias'), (int) $id_address, (int) $this->context->customer->id)) {
$this->errors[] = sprintf(Tools::displayError('The alias "%s" has already been used. Please select another one.'), Tools::safeOutput(Tools::getValue('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 !
if ($this->errors && !$this->ajax) {
return;
}
// If we edit this address, delete old address and create a new one
if (Validate::isLoadedObject($this->_address)) {
if (Validate::isLoadedObject($country) && !$country->contains_states) {
$address->id_state = 0;
}
$address_old = $this->_address;
if (Customer::customerHasAddress($this->context->customer->id, (int) $address_old->id)) {
if ($address_old->isUsed()) {
$address_old->delete();
} else {
$address->id = (int) $address_old->id;
$address->date_add = $address_old->date_add;
}
}
}
if ($this->ajax && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$this->errors = array_unique(array_merge($this->errors, $address->validateController()));
if (count($this->errors)) {
$return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors);
$this->ajaxDie(Tools::jsonEncode($return));
}
}
// Save address
if ($result = $address->save()) {
// Update id address of the current cart if necessary
if (isset($address_old) && $address_old->isUsed()) {
$this->context->cart->updateAddressId($address_old->id, $address->id);
} else {
// Update cart address
$this->context->cart->autosetProductAddress();
}
if ((bool) Tools::getValue('select_address', false) == true || Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$this->context->cart->id_address_invoice = (int) $address->id;
} elseif (Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$this->context->cart->id_address_invoice = (int) $this->context->cart->id_address_delivery;
}
$this->context->cart->update();
if ($this->ajax) {
$return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => (int) $this->context->cart->id_address_delivery, 'id_address_invoice' => (int) $this->context->cart->id_address_invoice);
$this->ajaxDie(Tools::jsonEncode($return));
}
// Redirect to old page or current page
if ($back = Tools::getValue('back')) {
if ($back == Tools::secureReferrer(Tools::getValue('back'))) {
Tools::redirect(html_entity_decode($back));
}
$mod = Tools::getValue('mod');
Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
} else {
Tools::redirect('index.php?controller=addresses');
}
//.........这里部分代码省略.........
示例4: processSubmitAddress
/**
* Process changes on an address
*/
protected function processSubmitAddress()
{
/*if ($this->context->customer->is_guest)
Tools::redirect('index.php?controller=addresses');*/
$address = new Address();
$this->errors = $address->validateController();
$address->id_customer = (int) $this->context->customer->id;
// Check page token
if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
$this->errors[] = Tools::displayError('Invalid token');
}
// Check phone
if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
$this->errors[] = Tools::displayError('You must register at least one phone number');
}
if ($address->id_country) {
// Check country
if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
throw new PrestaShopException('Country cannot be loaded with address->id_country');
}
if ((int) $country->contains_states && !(int) $address->id_state) {
$this->errors[] = Tools::displayError('This country requires a state selection.');
}
// US customer: normalize the address
if ($address->id_country == Country::getByIso('US')) {
include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
$normalize = new AddressStandardizationSolution();
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
// Check country zip code
$zip_code_format = $country->zip_code_format;
if ($country->need_zip_code) {
if (($postcode = Tools::getValue('postcode')) && $zip_code_format) {
if (!$country->checkZipCode($postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
} else {
if ($zip_code_format) {
$this->errors[] = Tools::displayError('Zip/Postal code is required.');
} else {
if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
}
}
}
// Check country DNI
if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
} else {
if (!$country->isNeedDni()) {
$address->dni = null;
}
}
}
// Check if the alias exists
if (!empty($_POST['alias']) && (int) $this->context->customer->id > 0 && Db::getInstance()->getValue('
SELECT count(*)
FROM ' . _DB_PREFIX_ . 'address
WHERE `alias` = \'' . pSql($_POST['alias']) . '\'
AND id_address != ' . (int) Tools::getValue('id_address') . '
AND id_customer = ' . (int) $this->context->customer->id . '
AND deleted = 0') > 0) {
$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 !
if ($this->errors && !$this->ajax) {
return;
}
// If we edit this address, delete old address and create a new one
if (Validate::isLoadedObject($this->_address)) {
if (Validate::isLoadedObject($country) && !$country->contains_states) {
$address->id_state = 0;
}
$address_old = $this->_address;
if (Customer::customerHasAddress($this->context->customer->id, (int) $address_old->id)) {
if ($address_old->isUsed()) {
$address_old->delete();
} else {
$address->id = (int) $address_old->id;
$address->date_add = $address_old->date_add;
}
}
}
// Save address
if ($result = $address->save()) {
// Update id address of the current cart if necessary
if (isset($address_old) && $address_old->isUsed()) {
$this->context->cart->updateAddressId($address_old->id, $address->id);
} else {
// Update cart address
$this->context->cart->autosetProductAddress();
}
if ($this->ajax) {
//.........这里部分代码省略.........
示例5: _processSubmitAddress
protected function _processSubmitAddress($id_address, $type)
{
if (isset($id_address) && $id_address > 0) {
$address = new Address($id_address);
} else {
$address = new Address();
}
$this->errors = $address->validateController();
$fields_to_check = array("address2", "company", "vat_number", "phone", "phone_mobile", "other");
foreach ($fields_to_check as $field1) {
if (Tools::getValue($field1) && trim(Tools::getValue($field1)) == "") {
$address->{$field1} = "";
}
}
if (empty($this->errors)) {
// So that dummyvalue address doesn't get customer id assigned
$address->id_customer = (int) $this->context->customer->id;
}
if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
$this->errors[] = Tools::displayError('Invalid token');
}
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile') && !Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && $type == 'delivery') {
$this->errors[] = Tools::displayError('You must register at least one phone number');
}
if ($address->id_country) {
if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
throw new PrestaShopException('Country cannot be loaded with address->id_country');
}
if ((int) $country->contains_states && !(int) $address->id_state) {
$this->errors[] = Tools::displayError('This country requires a state selection.');
}
if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
$normalize = new AddressStandardizationSolution();
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
$zip_code_format = $country->zip_code_format;
if ($country->need_zip_code) {
if (($postcode = trim(Tools::getValue('postcode'))) && $zip_code_format) {
if (!$country->checkZipCode($postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
} else {
if ($zip_code_format && !$this->context->cart->isVirtualCart()) {
$this->errors[] = Tools::displayError('Zip/Postal code is required.');
} else {
if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
}
}
}
}
if (isset($id_address) && $id_address > 0) {
$alias_id_address = $id_address;
} else {
$alias_id_address = (int) Tools::getValue('id_address');
}
if (!$this->context->customer->is_guest && Tools::getValue('alias') && (int) $this->context->customer->id > 0 && Db::getInstance()->getValue('
SELECT count(*)
FROM ' . _DB_PREFIX_ . 'address
WHERE `alias` = \'' . pSql(Tools::getValue('alias')) . '\'
AND id_address != ' . $alias_id_address . '
AND id_customer = ' . (int) $this->context->customer->id . '
AND deleted = 0') > 0) {
$address->alias .= '_' . $alias_id_address;
}
$this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
if ($this->errors) {
if ($this->ajax) {
$return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
die(Tools::jsonEncode($return));
} else {
return;
}
}
$this->context->cart->setNoMultishipping();
// As the cart is no multishipping, set each delivery address lines with the main delivery address
$address->alias = preg_replace('/[!<>?=+@{}_$%]/', '', $address->alias);
if ($result = $address->save()) {
if (isset($address_old) && $address_old->isUsed()) {
$this->context->cart->updateAddressId($address_old->id, $address->id);
} else {
// Update cart address
$this->context->cart->autosetProductAddress();
}
if ($this->ajax) {
$return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
die(Tools::jsonEncode($return));
}
if ($back = Tools::getValue('back')) {
$mod = Tools::getValue('mod');
Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
} else {
Tools::redirect('index.php?controller=addresses');
}
}
$this->errors[] = Tools::displayError('An error occurred while updating your address.');
}
示例6: _processSubmitAddress
protected function _processSubmitAddress($id_address, $type)
{
/*if ($this->context->customer->is_guest)
Tools::redirect('index.php?controller=addresses');*/
if (isset($id_address) && $id_address > 0) {
$address = new Address($id_address);
} else {
$address = new Address();
}
$this->errors = $address->validateController();
// Update address2 and company if they're empty (non mandatory fields) - default validateController ignores them
$fields_to_check = array("address2", "company", "vat_number", "phone", "phone_mobile", "other");
foreach ($fields_to_check as $field1) {
if (Tools::getValue($field1) && trim(Tools::getValue($field1)) == "") {
$address->{$field1} = "";
}
}
if (empty($this->errors)) {
// So that dummyvalue address doesn't get customer id assigned
$address->id_customer = (int) $this->context->customer->id;
}
// Check page token
if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
$this->errors[] = Tools::displayError('Invalid token');
}
// Check phone
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile') && !Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && $type == 'delivery') {
$this->errors[] = Tools::displayError('You must register at least one phone number');
}
if ($address->id_country) {
// Check country
if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
throw new PrestaShopException('Country cannot be loaded with address->id_country');
}
if ((int) $country->contains_states && !(int) $address->id_state) {
$this->errors[] = Tools::displayError('This country requires a state selection.');
}
// US customer: normalize the address
if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
$normalize = new AddressStandardizationSolution();
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
// Check country zip code
$zip_code_format = $country->zip_code_format;
if ($country->need_zip_code) {
if (($postcode = trim(Tools::getValue('postcode'))) && $zip_code_format) {
if (!$country->checkZipCode($postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
} else {
if ($zip_code_format && !$this->context->cart->isVirtualCart()) {
$this->errors[] = Tools::displayError('Zip/Postal code is required.');
} else {
if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
}
}
}
// Check country DNI
/*if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
else if (!$country->isNeedDni())
$address->dni = null;*/
}
if (isset($id_address) && $id_address > 0) {
$alias_id_address = $id_address;
} else {
$alias_id_address = (int) Tools::getValue('id_address');
}
// Check if the alias exists
if (!$this->context->customer->is_guest && Tools::getValue('alias') && (int) $this->context->customer->id > 0 && Db::getInstance()->getValue('
SELECT count(*)
FROM ' . _DB_PREFIX_ . 'address
WHERE `alias` = \'' . pSql(Tools::getValue('alias')) . '\'
AND id_address != ' . $alias_id_address . '
AND id_customer = ' . (int) $this->context->customer->id . '
AND deleted = 0') > 0) {
$address->alias .= '_' . $alias_id_address;
}
//$this->errors[] = sprintf(Tools::displayError('The alias "%s" is already used, please chose another one.'), Tools::safeOutput(Tools::getValue('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 !
if ($this->errors) {
if ($this->ajax) {
$return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice);
die(Tools::jsonEncode($return));
} else {
return;
}
}
// If we edit this address, delete old address and create a new one
/*if (Validate::isLoadedObject($this->_address))
{
if (Validate::isLoadedObject($country) && !$country->contains_states)
$address->id_state = 0;
$address_old = $this->_address;
//.........这里部分代码省略.........