Added :Nationality field added

This commit is contained in:
azhar bhat
2026-08-18 17:23:52 +05:30
parent a1ceb1b2a9
commit 3a59b8a011
9 changed files with 141 additions and 2 deletions

View File

@@ -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)

View File

@@ -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.'),

View File

@@ -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());

View File

@@ -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)

View File

@@ -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'));

View File

@@ -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),

View File

@@ -911,6 +911,12 @@
<configuration id="PS_CUSTOMER_BIRTHDATE" name="PS_CUSTOMER_BIRTHDATE">
<value>1</value>
</configuration>
<configuration id="PS_CUSTOMER_NATIONALITY" name="PS_CUSTOMER_NATIONALITY">
<value>1</value>
</configuration>
<configuration id="PS_CUSTOMER_NATIONALITY_MANDATORY" name="PS_CUSTOMER_NATIONALITY_MANDATORY">
<value>0</value>
</configuration>
<configuration id="PS_CUSTOMER_NWSL" name="PS_CUSTOMER_NWSL">
<value>1</value>
</configuration>

View File

@@ -156,6 +156,17 @@
<label for="lastname">{l s='Last name'} <sup>*</sup></label>
<input type="text" class="is_required validate form-control" data-validate="isName" id="lastname" name="lastname" value="{if isset($smarty.post.lastname)}{$smarty.post.lastname}{/if}" />
</div>
{if isset($nationality) && $nationality}
<div class="form-group">
<label for="id_nationality">{l s='Nationality'}{if isset($nationality_mandatory) && $nationality_mandatory} <sup>*</sup>{/if}</label>
<select name="id_nationality" id="id_nationality" class="form-control">
<option value="">-</option>
{foreach from=$nationality_countries item=c}
<option value="{$c.id_country}" {if isset($smarty.post.id_nationality) && $smarty.post.id_nationality == $c.id_country} selected="selected"{/if}>{$c.name}</option>
{/foreach}
</select>
</div>
{/if}
<div class="form-group date-select">
<label>{l s='Date of Birth'}</label>
<div class="row">
@@ -497,6 +508,17 @@
<input type="password" class="is_required validate form-control" data-validate="isPasswd" name="passwd" id="passwd" />
<span class="form_info">{l s='(Five characters minimum)'}</span>
</div>
{if isset($nationality) && $nationality}
<div class="form-group">
<label for="id_nationality">{l s='Nationality'}{if isset($nationality_mandatory) && $nationality_mandatory} <sup>*</sup>{/if}</label>
<select name="id_nationality" id="id_nationality" class="form-control">
<option value="">-</option>
{foreach from=$nationality_countries item=c}
<option value="{$c.id_country}" {if isset($smarty.post.id_nationality) && $smarty.post.id_nationality == $c.id_country} selected="selected"{/if}>{$c.name}</option>
{/foreach}
</select>
</div>
{/if}
{if isset($birthday) && $birthday}
<div class="form-group">
<label>{l s='Date of Birth'}</label>

View File

@@ -95,6 +95,22 @@
</label>
<input class="is_required validate form-control" data-validate="isPhoneNumber" type="phone" name="phone" id="phone" value="{$smarty.post.phone}" />
</div>
{if isset($nationality) && $nationality}
<div class="form-group">
<label for="id_nationality">
{l s='Nationality'}
{if isset($nationality_mandatory) && $nationality_mandatory}
<sup>*</sup>
{/if}
</label>
<select name="id_nationality" id="id_nationality" class="form-control">
<option value="">-</option>
{foreach from=$nationality_countries item=c}
<option value="{$c.id_country}" {if isset($smarty.post.id_nationality) && $smarty.post.id_nationality == $c.id_country} selected="selected"{/if}>{$c.name}</option>
{/foreach}
</select>
</div>
{/if}
{if isset($birthday) && $birthday}
<div class="form-group">
<label>