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