From f5f87d5fcf46aad7b6a349d0ce067de608287f8e Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Thu, 20 Aug 2026 12:23:27 +0530 Subject: [PATCH] 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),