From 3a59b8a01124ecf7f47c05f7c1d9d76a98cb04ad Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Tue, 18 Aug 2026 17:23:52 +0530 Subject: [PATCH 1/7] Added :Nationality field added --- classes/Customer.php | 8 +++ .../AdminCustomerPreferencesController.php | 14 +++++ .../admin/AdminCustomersController.php | 62 ++++++++++++++++++- controllers/front/AuthController.php | 7 +++ controllers/front/IdentityController.php | 7 +++ install/data/db_structure.sql | 1 + install/data/xml/configuration.xml | 6 ++ .../authentication.tpl | 22 +++++++ themes/hotel-reservation-theme/identity.tpl | 16 +++++ 9 files changed, 141 insertions(+), 2 deletions(-) diff --git a/classes/Customer.php b/classes/Customer.php index d5644633b..608f27cc4 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -41,6 +41,9 @@ class CustomerCore extends ObjectModel /** @var int Gender ID */ public $id_gender = 0; + /** @var int Nationality (Country) ID */ + public $id_nationality = 0; + /** @var int Default group ID */ public $id_default_group; @@ -170,6 +173,7 @@ class CustomerCore extends ObjectModel 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 60), 'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false), 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_nationality' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'), 'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_post' => false), @@ -209,6 +213,10 @@ class CustomerCore extends ObjectModel if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) { self::$definition['fields']['phone']['required'] = true; } + + if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')) { + self::$definition['fields']['id_nationality']['required'] = true; + } } public function validateFields($die = true, $error_return = false) diff --git a/controllers/admin/AdminCustomerPreferencesController.php b/controllers/admin/AdminCustomerPreferencesController.php index 7fd12828e..dc14150e6 100644 --- a/controllers/admin/AdminCustomerPreferencesController.php +++ b/controllers/admin/AdminCustomerPreferencesController.php @@ -107,6 +107,20 @@ class AdminCustomerPreferencesControllerCore extends AdminController 'cast' => 'intval', 'type' => 'bool' ), + 'PS_CUSTOMER_NATIONALITY' => array( + 'title' => $this->l('Enable nationality'), + 'hint' => $this->l('Display or not the nationality field.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool' + ), + 'PS_CUSTOMER_NATIONALITY_MANDATORY' => array( + 'title' => $this->l('Nationality is mandatory'), + 'hint' => $this->l('If you choose yes, your customer will have to select their nationality.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool' + ), 'PS_CUSTOMER_NWSL' => array( 'title' => $this->l('Enable newsletter registration'), 'hint' => $this->l('Display or not the newsletter registration tick box.'), diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index b013b3fe8..8acc8de3f 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -77,12 +77,37 @@ class AdminCustomersControllerCore extends AdminController $groups_array[$group['id_group']] = $group['name']; } + $selected_nationalities = array(); + $nationalities_result = Db::getInstance()->executeS(' + SELECT DISTINCT cl.id_country, cl.name + FROM '._DB_PREFIX_.'customer c + INNER JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = c.id_nationality AND cl.id_lang = '.(int)$this->context->language->id.') + WHERE c.id_nationality != 0 AND c.deleted = 0 + ORDER BY cl.name ASC + '); + foreach ($nationalities_result as $row) { + $selected_nationalities[$row['id_country']] = $row['name']; + } + + $selected_countries = array(); + $countries_result = Db::getInstance()->executeS(' + SELECT DISTINCT cl.id_country, cl.name + FROM '._DB_PREFIX_.'address ad + INNER JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = ad.id_country AND cl.id_lang = '.(int)$this->context->language->id.') + WHERE ad.deleted = 0 + ORDER BY cl.name ASC + '); + foreach ($countries_result as $row) { + $selected_countries[$row['id_country']] = $row['name']; + } + $this->_join = 'LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON (a.id_gender = gl.id_gender AND gl.id_lang = '.(int)$this->context->language->id.')'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'group_lang grl ON (a.id_default_group = grl.id_group AND grl.id_lang = '.(int)$this->context->language->id.')'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'orders o ON (a.id_customer = o.id_customer)'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'address ad ON (ad.id_customer = a.id_customer AND ad.deleted = 0)'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'state adstate ON (adstate.id_state = ad.id_state)'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'country_lang adcountry ON (adcountry.id_country = ad.id_country AND adcountry.id_lang = '.(int)$this->context->language->id.')'; + $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'country_lang natcountry ON (natcountry.id_country = a.id_nationality AND natcountry.id_lang = '.(int)$this->context->language->id.')'; $this->_group = 'GROUP BY a.`id_customer`'; $this->fields_list = array( @@ -134,6 +159,16 @@ class AdminCustomersControllerCore extends AdminController 'list' => $groups_array, 'filter_key' => 'a!id_default_group', ), + 'nationality' => array( + 'title' => $this->l('Nationality'), + 'optional' => true, + 'visible_default' => false, + 'type' => 'select', + 'list' => $selected_nationalities, + 'filter_key' => 'a!id_nationality', + 'filter_type' => 'int', + 'orderby' => false, + ), 'total_orders' => array( 'title' => $this->l('Number of orders'), 'type' => 'range', @@ -205,7 +240,10 @@ class AdminCustomersControllerCore extends AdminController 'title' => $this->l('Country'), 'optional' => true, 'visible_default' => false, - 'havingFilter' => true, + 'type' => 'select', + 'list' => $selected_countries, + 'filter_key' => 'ad!id_country', + 'filter_type' => 'int', 'orderby' => false, ), 'address_phone' => array( @@ -299,7 +337,7 @@ class AdminCustomersControllerCore extends AdminController ad.company as address_company, ad.vat_number, ad.address1, ad.address2, ad.city, adstate.name as state, ad.postcode, adcountry.name as country, ad.phone as address_phone, - ad.phone_mobile, ad.dni'; + ad.phone_mobile, ad.dni, natcountry.name as nationality'; // Check if we can add a customer if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) { @@ -585,6 +623,22 @@ class AdminCustomersControllerCore extends AdminController 'years' => $years ) ), + array( + 'type' => 'select', + 'label' => $this->l('Nationality'), + 'name' => 'id_nationality', + 'required' => (bool)(Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')), + 'col' => '4', + 'options' => array( + 'query' => Country::getCountries($this->context->language->id), + 'id' => 'id_country', + 'name' => 'name', + 'default' => array( + 'value' => '', + 'label' => $this->l('-- Choose --') + ) + ), + ), array( 'type' => 'switch', 'label' => $this->l('Enabled'), @@ -1326,6 +1380,10 @@ class AdminCustomersControllerCore extends AdminController } } + if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY') && !Tools::getValue('id_nationality')) { + $this->errors[] = Tools::displayError('Nationality is required.'); + } + $customer = new Customer(); $this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase()); diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 91b583007..efc40193e 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -106,6 +106,9 @@ class AuthControllerCore extends FrontController $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); + $this->context->smarty->assign('nationality', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY')); + $this->context->smarty->assign('nationality_mandatory', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')); + $this->context->smarty->assign('nationality_countries', Country::getCountries($this->context->language->id)); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); @@ -429,6 +432,10 @@ class AuthControllerCore extends FrontController $this->errors[] = Tools::displayError('Phone number is required.'); } + if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY') && !Tools::getValue('id_nationality')) { + $this->errors[] = Tools::displayError('Nationality is required.'); + } + if (!Tools::getValue('is_new_customer', 1)) { if (Validate::isEmail($email = Tools::getValue('email')) && $idCustomer = Customer::customerExists(Tools::getValue('email'), true, false) diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index b24881336..25e6eeeb5 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -63,6 +63,10 @@ class IdentityControllerCore extends FrontController } } + if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY') && !Tools::getValue('id_nationality')) { + $this->errors[] = Tools::displayError('Nationality is required.'); + } + if (Tools::getIsset('old_passwd')) { $old_passwd = trim(Tools::getValue('old_passwd')); } @@ -167,6 +171,9 @@ class IdentityControllerCore extends FrontController $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); + $this->context->smarty->assign('nationality', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY')); + $this->context->smarty->assign('nationality_mandatory', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')); + $this->context->smarty->assign('nationality_countries', Country::getCountries($this->context->language->id)); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 55f952897..2e967692a 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -587,6 +587,7 @@ CREATE TABLE `PREFIX_customer` ( `id_gender` int(10) unsigned NOT NULL, `id_default_group` int(10) unsigned NOT NULL DEFAULT '1', `id_lang` int(10) unsigned NULL, + `id_nationality` int(10) unsigned NOT NULL DEFAULT '0', `id_risk` int(10) unsigned NOT NULL DEFAULT '1', `company` varchar(64), `siret` varchar(14), diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 9e5658518..da4f48339 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -911,6 +911,12 @@ 1 + + 1 + + + 0 + 1 diff --git a/themes/hotel-reservation-theme/authentication.tpl b/themes/hotel-reservation-theme/authentication.tpl index 14baff140..9c3dba59d 100644 --- a/themes/hotel-reservation-theme/authentication.tpl +++ b/themes/hotel-reservation-theme/authentication.tpl @@ -156,6 +156,17 @@ + {if isset($nationality) && $nationality} +
+ + +
+ {/if}
@@ -497,6 +508,17 @@ {l s='(Five characters minimum)'}
+ {if isset($nationality) && $nationality} +
+ + +
+ {/if} {if isset($birthday) && $birthday}
diff --git a/themes/hotel-reservation-theme/identity.tpl b/themes/hotel-reservation-theme/identity.tpl index a8d12a50d..50351fc0a 100644 --- a/themes/hotel-reservation-theme/identity.tpl +++ b/themes/hotel-reservation-theme/identity.tpl @@ -95,6 +95,22 @@
+ {if isset($nationality) && $nationality} +
+ + +
+ {/if} {if isset($birthday) && $birthday}
{if isset($nationality) && $nationality} -
+
diff --git a/themes/hotel-reservation-theme/identity.tpl b/themes/hotel-reservation-theme/identity.tpl index 50351fc0a..cc3d31aaf 100644 --- a/themes/hotel-reservation-theme/identity.tpl +++ b/themes/hotel-reservation-theme/identity.tpl @@ -96,12 +96,9 @@
{if isset($nationality) && $nationality} -
-
+
+ +
+

{if $nationality}{$nationality}{else}{l s='Unknown'}{/if}

+
+
diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 8acc8de3f..05bd2db10 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -996,6 +996,14 @@ class AdminCustomersControllerCore extends AdminController $gender = new Gender($customer->id_gender, $this->context->language->id); $gender_image = $gender->getImage(); + $nationality = ''; + if ($customer->id_nationality) { + $nationalityCountry = new Country($customer->id_nationality, $this->context->language->id); + if (Validate::isLoadedObject($nationalityCountry)) { + $nationality = $nationalityCountry->name; + } + } + $customer_stats = $customer->getStats(); $sql = 'SELECT SUM(total_paid_real) FROM '._DB_PREFIX_.'orders WHERE id_customer = %d AND valid = 1'; if ($total_customer = Db::getInstance()->getValue(sprintf($sql, $customer->id))) { @@ -1145,6 +1153,7 @@ class AdminCustomersControllerCore extends AdminController 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday), + 'nationality' => $nationality, 'last_update' => Tools::displayDate($customer->date_upd, null, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => $customer->id_lang, From f5f87d5fcf46aad7b6a349d0ce067de608287f8e Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Thu, 20 Aug 2026 12:23:27 +0530 Subject: [PATCH 4/7] database column updated --- classes/Customer.php | 8 ++++---- controllers/admin/AdminCustomersController.php | 16 ++++++++-------- controllers/front/AuthController.php | 2 ++ controllers/front/IdentityController.php | 2 ++ controllers/front/OrderOpcController.php | 3 ++- install/data/db_structure.sql | 2 +- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/classes/Customer.php b/classes/Customer.php index 608f27cc4..d397b5972 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -41,8 +41,8 @@ class CustomerCore extends ObjectModel /** @var int Gender ID */ public $id_gender = 0; - /** @var int Nationality (Country) ID */ - public $id_nationality = 0; + /** @var int Nationality, stored as a country ID */ + public $id_country = 0; /** @var int Default group ID */ public $id_default_group; @@ -173,7 +173,7 @@ class CustomerCore extends ObjectModel 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 60), 'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false), 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_nationality' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false), 'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'), 'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_post' => false), @@ -215,7 +215,7 @@ class CustomerCore extends ObjectModel } if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')) { - self::$definition['fields']['id_nationality']['required'] = true; + self::$definition['fields']['id_country']['required'] = true; } } diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 05bd2db10..66f695ed1 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -81,8 +81,8 @@ class AdminCustomersControllerCore extends AdminController $nationalities_result = Db::getInstance()->executeS(' SELECT DISTINCT cl.id_country, cl.name FROM '._DB_PREFIX_.'customer c - INNER JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = c.id_nationality AND cl.id_lang = '.(int)$this->context->language->id.') - WHERE c.id_nationality != 0 AND c.deleted = 0 + INNER JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = c.id_country AND cl.id_lang = '.(int)$this->context->language->id.') + WHERE c.id_country != 0 AND c.deleted = 0 ORDER BY cl.name ASC '); foreach ($nationalities_result as $row) { @@ -107,7 +107,7 @@ class AdminCustomersControllerCore extends AdminController $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'address ad ON (ad.id_customer = a.id_customer AND ad.deleted = 0)'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'state adstate ON (adstate.id_state = ad.id_state)'; $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'country_lang adcountry ON (adcountry.id_country = ad.id_country AND adcountry.id_lang = '.(int)$this->context->language->id.')'; - $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'country_lang natcountry ON (natcountry.id_country = a.id_nationality AND natcountry.id_lang = '.(int)$this->context->language->id.')'; + $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'country_lang natcountry ON (natcountry.id_country = a.id_country AND natcountry.id_lang = '.(int)$this->context->language->id.')'; $this->_group = 'GROUP BY a.`id_customer`'; $this->fields_list = array( @@ -165,7 +165,7 @@ class AdminCustomersControllerCore extends AdminController 'visible_default' => false, 'type' => 'select', 'list' => $selected_nationalities, - 'filter_key' => 'a!id_nationality', + 'filter_key' => 'a!id_country', 'filter_type' => 'int', 'orderby' => false, ), @@ -626,7 +626,7 @@ class AdminCustomersControllerCore extends AdminController array( 'type' => 'select', 'label' => $this->l('Nationality'), - 'name' => 'id_nationality', + 'name' => 'id_country', 'required' => (bool)(Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')), 'col' => '4', 'options' => array( @@ -997,8 +997,8 @@ class AdminCustomersControllerCore extends AdminController $gender_image = $gender->getImage(); $nationality = ''; - if ($customer->id_nationality) { - $nationalityCountry = new Country($customer->id_nationality, $this->context->language->id); + if ($customer->id_country) { + $nationalityCountry = new Country($customer->id_country, $this->context->language->id); if (Validate::isLoadedObject($nationalityCountry)) { $nationality = $nationalityCountry->name; } @@ -1389,7 +1389,7 @@ class AdminCustomersControllerCore extends AdminController } } - if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY') && !Tools::getValue('id_nationality')) { + if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY') && !Tools::getValue('id_country')) { $this->errors[] = Tools::displayError('Nationality is required.'); } diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index efc40193e..c92a6d12f 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -468,6 +468,7 @@ class AuthControllerCore extends FrontController if (!count($this->errors)) { $customer->phone = Tools::getValue('phone'); + $customer->id_country = (int)Tools::getValue('id_nationality'); if ($customer->add()) { if (!$customer->is_guest) { if (!$this->sendConfirmationMail($customer)) { @@ -614,6 +615,7 @@ class AuthControllerCore extends FrontController $customer->is_guest = 0; } $customer->phone = Tools::getValue('phone'); + $customer->id_country = (int)Tools::getValue('id_nationality'); if (!$customer->save()) { $this->errors[] = Tools::displayError('An error occurred while creating your account.'); } else { diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index 25e6eeeb5..90de6f31d 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -95,6 +95,7 @@ class IdentityControllerCore extends FrontController if (!count($this->errors)) { $this->customer->phone = $phone; + $this->customer->id_country = (int)Tools::getValue('id_nationality'); $this->customer->id_default_group = (int)$prev_id_default_group; $this->customer->firstname = Tools::ucwords($this->customer->firstname); @@ -131,6 +132,7 @@ class IdentityControllerCore extends FrontController } else { $_POST = array_map('stripslashes', $this->customer->getFields()); $_POST['phone'] = $this->customer->phone; + $_POST['id_nationality'] = $this->customer->id_country; } return $this->customer; diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 77f99533f..26132c846 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -126,6 +126,7 @@ class OrderOpcControllerCore extends ParentOrderController } $this->context->customer->phone = $phone; + $this->context->customer->id_country = (int)Tools::getValue('id_nationality'); $_POST['lastname'] = $_POST['customer_lastname']; $_POST['firstname'] = $_POST['customer_firstname']; $this->errors = array_merge($this->errors, $this->context->customer->validateController()); @@ -648,7 +649,7 @@ class OrderOpcControllerCore extends ParentOrderController 'id_country' => (int)$address_delivery->id_country, 'id_state' => (int)$address_delivery->id_state, 'id_gender' => (int)$customer->id_gender, - 'id_nationality' => (int)$customer->id_nationality, + 'id_nationality' => (int)$customer->id_country, 'phone' => $customer->phone, 'sl_year' => $birthday[0], 'sl_month' => $birthday[1], diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 2e967692a..ce4b9b2e8 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -587,7 +587,7 @@ CREATE TABLE `PREFIX_customer` ( `id_gender` int(10) unsigned NOT NULL, `id_default_group` int(10) unsigned NOT NULL DEFAULT '1', `id_lang` int(10) unsigned NULL, - `id_nationality` int(10) unsigned NOT NULL DEFAULT '0', + `id_country` int(10) unsigned NOT NULL DEFAULT '0', `id_risk` int(10) unsigned NOT NULL DEFAULT '1', `company` varchar(64), `siret` varchar(14), From 211e82380b2db2ca82aa69cc38f6bb4dfa8d2e8c Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Mon, 24 Aug 2026 18:05:11 +0530 Subject: [PATCH 5/7] add other option in nationalities --- .../controllers/customers/helpers/view/view.tpl | 2 +- classes/Customer.php | 12 +++++++++++- controllers/admin/AdminCustomersController.php | 10 +++++++--- controllers/front/AuthController.php | 2 +- controllers/front/IdentityController.php | 2 +- controllers/front/OrderOpcController.php | 2 +- install/data/db_structure.sql | 2 +- install/data/xml/configuration.xml | 2 +- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl index 21f0a162e..afedb3edd 100644 --- a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl @@ -75,7 +75,7 @@
-

{if $nationality}{$nationality}{else}{l s='Unknown'}{/if}

+

{if $nationality}{$nationality}{else}--{/if}

diff --git a/classes/Customer.php b/classes/Customer.php index d397b5972..f67ad0c57 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -173,7 +173,7 @@ class CustomerCore extends ObjectModel 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 60), 'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false), 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false), + 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'copy_post' => false), 'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'), 'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_post' => false), @@ -838,6 +838,16 @@ class CustomerCore extends ObjectModel return (int) Configuration::get('PS_COUNTRY_DEFAULT'); } + public static function getNationalities($id_lang) + { + $nationalities = Country::getCountries((int) $id_lang); + $nationalities[-1] = array( + 'id_country' => -1, + 'name' => Translate::getAdminTranslation('Other', 'AdminCustomersController'), + ); + + return $nationalities; + } public function toggleStatus() { diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 66f695ed1..b2589f681 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -88,6 +88,7 @@ class AdminCustomersControllerCore extends AdminController foreach ($nationalities_result as $row) { $selected_nationalities[$row['id_country']] = $row['name']; } + $selected_nationalities[-1] = $this->l('Other'); $selected_countries = array(); $countries_result = Db::getInstance()->executeS(' @@ -337,7 +338,8 @@ class AdminCustomersControllerCore extends AdminController ad.company as address_company, ad.vat_number, ad.address1, ad.address2, ad.city, adstate.name as state, ad.postcode, adcountry.name as country, ad.phone as address_phone, - ad.phone_mobile, ad.dni, natcountry.name as nationality'; + ad.phone_mobile, ad.dni, + (CASE WHEN a.id_country = -1 THEN \''.pSQL($this->l('Other')).'\' ELSE natcountry.name END) as nationality'; // Check if we can add a customer if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) { @@ -630,7 +632,7 @@ class AdminCustomersControllerCore extends AdminController 'required' => (bool)(Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')), 'col' => '4', 'options' => array( - 'query' => Country::getCountries($this->context->language->id), + 'query' => Customer::getNationalities($this->context->language->id), 'id' => 'id_country', 'name' => 'name', 'default' => array( @@ -997,7 +999,9 @@ class AdminCustomersControllerCore extends AdminController $gender_image = $gender->getImage(); $nationality = ''; - if ($customer->id_country) { + if ($customer->id_country == -1) { + $nationality = Translate::getAdminTranslation('Other', 'AdminCustomersController'); + } elseif ($customer->id_country) { $nationalityCountry = new Country($customer->id_country, $this->context->language->id); if (Validate::isLoadedObject($nationalityCountry)) { $nationality = $nationalityCountry->name; diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index c92a6d12f..41258d478 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -108,7 +108,7 @@ class AuthControllerCore extends FrontController $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); $this->context->smarty->assign('nationality', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY')); $this->context->smarty->assign('nationality_mandatory', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')); - $this->context->smarty->assign('nationality_countries', Country::getCountries($this->context->language->id)); + $this->context->smarty->assign('nationality_countries', Customer::getNationalities($this->context->language->id)); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index 90de6f31d..0e29de05a 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -175,7 +175,7 @@ class IdentityControllerCore extends FrontController $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); $this->context->smarty->assign('nationality', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY')); $this->context->smarty->assign('nationality_mandatory', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')); - $this->context->smarty->assign('nationality_countries', Country::getCountries($this->context->language->id)); + $this->context->smarty->assign('nationality_countries', Customer::getNationalities($this->context->language->id)); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 26132c846..782253ab5 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -562,7 +562,7 @@ class OrderOpcControllerCore extends ParentOrderController $this->context->smarty->assign('birthday', (bool) Configuration::get('PS_CUSTOMER_BIRTHDATE')); $this->context->smarty->assign('nationality', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY')); $this->context->smarty->assign('nationality_mandatory', (bool) Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')); - $this->context->smarty->assign('nationality_countries', Country::getCountries($this->context->language->id)); + $this->context->smarty->assign('nationality_countries', Customer::getNationalities($this->context->language->id)); $this->context->smarty->assign('newsletter', $newsletter); $this->context->smarty->assign('optin', (bool)Configuration::get('PS_CUSTOMER_OPTIN')); $this->context->smarty->assign('field_required', $this->context->customer->validateFieldsRequiredDatabase()); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index ce4b9b2e8..c9d8c7bb8 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -587,7 +587,7 @@ CREATE TABLE `PREFIX_customer` ( `id_gender` int(10) unsigned NOT NULL, `id_default_group` int(10) unsigned NOT NULL DEFAULT '1', `id_lang` int(10) unsigned NULL, - `id_country` int(10) unsigned NOT NULL DEFAULT '0', + `id_country` int(10) NOT NULL DEFAULT '0', `id_risk` int(10) unsigned NOT NULL DEFAULT '1', `company` varchar(64), `siret` varchar(14), diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index da4f48339..e6fb3f0c0 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -912,7 +912,7 @@ 1 - 1 + 0 0 From b7be5e149844925496cd136ccaf3f7872aed35c7 Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Thu, 27 Aug 2026 11:57:12 +0530 Subject: [PATCH 6/7] Fixed translation --- classes/Customer.php | 2 +- controllers/admin/AdminCustomersController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Customer.php b/classes/Customer.php index f67ad0c57..007f3215d 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -843,7 +843,7 @@ class CustomerCore extends ObjectModel $nationalities = Country::getCountries((int) $id_lang); $nationalities[-1] = array( 'id_country' => -1, - 'name' => Translate::getAdminTranslation('Other', 'AdminCustomersController'), + 'name' => Translate::getAdminTranslation('Other', 'AdminCustomers'), ); return $nationalities; diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index b2589f681..4346617cf 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -1000,7 +1000,7 @@ class AdminCustomersControllerCore extends AdminController $nationality = ''; if ($customer->id_country == -1) { - $nationality = Translate::getAdminTranslation('Other', 'AdminCustomersController'); + $nationality = Translate::getAdminTranslation('Other', 'AdminCustomers'); } elseif ($customer->id_country) { $nationalityCountry = new Country($customer->id_country, $this->context->language->id); if (Validate::isLoadedObject($nationalityCountry)) { From 85a7e777db5bcbd279e083e514a8841c29a75a0f Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Thu, 27 Aug 2026 15:07:38 +0530 Subject: [PATCH 7/7] Added :Show/hide nationality required field and add option for not selected Nationality in filter --- classes/Customer.php | 2 +- controllers/admin/AdminCustomersController.php | 1 + js/admin.js | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/classes/Customer.php b/classes/Customer.php index 007f3215d..752fd9605 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -173,7 +173,7 @@ class CustomerCore extends ObjectModel 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 60), 'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false), 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'copy_post' => false), + 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'), 'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_post' => false), diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 4346617cf..bb2fd3fc4 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -89,6 +89,7 @@ class AdminCustomersControllerCore extends AdminController $selected_nationalities[$row['id_country']] = $row['name']; } $selected_nationalities[-1] = $this->l('Other'); + $selected_nationalities[0] = $this->l('None'); $selected_countries = array(); $countries_result = Db::getInstance()->executeS(' diff --git a/js/admin.js b/js/admin.js index b42e2e297..26c8d29f9 100644 --- a/js/admin.js +++ b/js/admin.js @@ -504,6 +504,14 @@ function changeCMSActivationAuthorization() getE('PS_CONDITIONS_CMS_ID').disabled = 'disabled'; } +function toggleNationalityMandatoryField() +{ + if ($('#PS_CUSTOMER_NATIONALITY_on').prop('checked')) + $('#conf_id_PS_CUSTOMER_NATIONALITY_MANDATORY').closest('.form-group').show(); + else + $('#conf_id_PS_CUSTOMER_NATIONALITY_MANDATORY').closest('.form-group').hide(); +} + function changeOverbookingOrderAction() { if (getE('PS_OVERBOOKING_ORDER_ACTION').value == $("input[name='OVERBOOKING_ORDER_CANCEL_ACTION']").val()) @@ -998,6 +1006,10 @@ $(document).ready(function() if ($('.kpi-container').length) { refresh_kpis(); } + if ($('#PS_CUSTOMER_NATIONALITY_on').length) { + toggleNationalityMandatoryField(); + $('input[name="PS_CUSTOMER_NATIONALITY"]').on('change', toggleNationalityMandatoryField); + } }); function bindSwapSave()