From 265afeefca445f4b804400b7acf6542f47ff6731 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Mon, 10 Sep 2012 14:06:51 +0000 Subject: [PATCH] // Fix PSCFV-3976 git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17269 b9a71923-0436-4b27-9f14-aed3839534dd --- controllers/front/AddressController.php | 71 +++++++++++++------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 48289d54f..a90eb1ea1 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -126,50 +126,51 @@ class AddressControllerCore extends FrontController // Check phone if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')) $this->errors[] = Tools::displayError('You must register at least one phone number'); - - // 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')) + if ($address->id_country) { - include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php'); - $normalize = new AddressStandardizationSolution; - $address->address1 = $normalize->AddressLineStandardization($address->address1); - $address->address2 = $normalize->AddressLineStandardization($address->address2); - } + // Check country + if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) + throw new PrestaShopException('Country cannot be loaded with address->id_country'); - // 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 ((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')) { - if (!$country->checkZipCode($postcode)) + 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))) ); } - 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 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