[-] BO : you cannot create 2 states with the same iso code in the same country anymore #PSCFV-53
This commit is contained in:
+5
-5
@@ -113,13 +113,13 @@ class StateCore extends ObjectModel
|
|||||||
* @param string $iso_code Iso code
|
* @param string $iso_code Iso code
|
||||||
* @return integer state id
|
* @return integer state id
|
||||||
*/
|
*/
|
||||||
public static function getIdByIso($iso_code)
|
public static function getIdByIso($iso_code, $id_country = null)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->getValue('
|
return Db::getInstance()->getValue('
|
||||||
SELECT `id_state`
|
SELECT `id_state`
|
||||||
FROM `'._DB_PREFIX_.'state`
|
FROM `'._DB_PREFIX_.'state`
|
||||||
WHERE `iso_code` = \''.pSQL($iso_code).'\''
|
WHERE `iso_code` = \''.pSQL($iso_code).'\'
|
||||||
);
|
'.($id_country ? 'AND `id_country` = '.(int)$id_country : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -181,6 +181,18 @@ class AdminStatesControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if (!isset($this->table))
|
if (!isset($this->table))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Tools::getValue('id_'.$this->table))
|
||||||
|
{
|
||||||
|
if (Validate::isStateIsoCode(Tools::getValue('iso_code')) && State::getIdByIso(Tools::getValue('iso_code'), Tools::getValue('id_country')))
|
||||||
|
$this->errors[] = Tools::displayError('This ISO code already exists, you cannot create two states with the same ISO code in the same country');
|
||||||
|
}
|
||||||
|
else if (Validate::isStateIsoCode(Tools::getValue('iso_code')))
|
||||||
|
{
|
||||||
|
$id_state = State::getIdByIso(Tools::getValue('iso_code'), Tools::getValue('id_country'));
|
||||||
|
if ($id_state && $id_state != Tools::getValue('id_'.$this->table))
|
||||||
|
$this->errors[] = Tools::displayError('This ISO code already exists, you cannot create two states with the same ISO code in the same country');
|
||||||
|
}
|
||||||
|
|
||||||
/* Delete object */
|
/* Delete object */
|
||||||
if (isset($_GET['delete'.$this->table]))
|
if (isset($_GET['delete'.$this->table]))
|
||||||
|
|||||||
Reference in New Issue
Block a user