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 4f52451c7..afedb3edd 100644
--- a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl
+++ b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl
@@ -72,6 +72,12 @@
+
diff --git a/classes/Customer.php b/classes/Customer.php
index d5644633b..752fd9605 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, stored as a country ID */
+ public $id_country = 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_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),
@@ -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_country']['required'] = true;
+ }
}
public function validateFields($die = true, $error_return = false)
@@ -830,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', 'AdminCustomers'),
+ );
+
+ return $nationalities;
+ }
public function toggleStatus()
{
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..bb2fd3fc4 100644
--- a/controllers/admin/AdminCustomersController.php
+++ b/controllers/admin/AdminCustomersController.php
@@ -77,12 +77,39 @@ 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_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) {
+ $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('
+ 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_country AND natcountry.id_lang = '.(int)$this->context->language->id.')';
$this->_group = 'GROUP BY a.`id_customer`';
$this->fields_list = array(
@@ -134,6 +161,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_country',
+ 'filter_type' => 'int',
+ 'orderby' => false,
+ ),
'total_orders' => array(
'title' => $this->l('Number of orders'),
'type' => 'range',
@@ -205,7 +242,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 +339,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';
+ 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)) {
@@ -585,6 +626,22 @@ class AdminCustomersControllerCore extends AdminController
'years' => $years
)
),
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Nationality'),
+ 'name' => 'id_country',
+ 'required' => (bool)(Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY')),
+ 'col' => '4',
+ 'options' => array(
+ 'query' => Customer::getNationalities($this->context->language->id),
+ 'id' => 'id_country',
+ 'name' => 'name',
+ 'default' => array(
+ 'value' => '',
+ 'label' => $this->l('-- Choose --')
+ )
+ ),
+ ),
array(
'type' => 'switch',
'label' => $this->l('Enabled'),
@@ -942,6 +999,16 @@ class AdminCustomersControllerCore extends AdminController
$gender = new Gender($customer->id_gender, $this->context->language->id);
$gender_image = $gender->getImage();
+ $nationality = '';
+ if ($customer->id_country == -1) {
+ $nationality = Translate::getAdminTranslation('Other', 'AdminCustomers');
+ } elseif ($customer->id_country) {
+ $nationalityCountry = new Country($customer->id_country, $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))) {
@@ -1091,6 +1158,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,
@@ -1326,6 +1394,10 @@ class AdminCustomersControllerCore extends AdminController
}
}
+ if (Configuration::get('PS_CUSTOMER_NATIONALITY') && Configuration::get('PS_CUSTOMER_NATIONALITY_MANDATORY') && !Tools::getValue('id_country')) {
+ $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..41258d478 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', Customer::getNationalities($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)
@@ -461,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)) {
@@ -607,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 b24881336..0e29de05a 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'));
}
@@ -91,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);
@@ -127,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;
@@ -167,6 +173,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', 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 a7320cadc..9fa3e72f9 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());
@@ -549,6 +550,9 @@ class OrderOpcControllerCore extends ParentOrderController
$newsletter = Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active && Configuration::get('PS_CUSTOMER_NWSL');
$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', 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());
@@ -635,6 +639,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_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 7b5c1d473..07a270b34 100644
--- a/install/data/db_structure.sql
+++ b/install/data/db_structure.sql
@@ -594,6 +594,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) 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..e6fb3f0c0 100644
--- a/install/data/xml/configuration.xml
+++ b/install/data/xml/configuration.xml
@@ -911,6 +911,12 @@
1
+
+ 0
+
+
+ 0
+
1
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()
diff --git a/themes/hotel-reservation-theme/authentication.tpl b/themes/hotel-reservation-theme/authentication.tpl
index 14baff140..c4383da00 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..cc3d31aaf 100644
--- a/themes/hotel-reservation-theme/identity.tpl
+++ b/themes/hotel-reservation-theme/identity.tpl
@@ -95,6 +95,19 @@
+ {if isset($nationality) && $nationality}
+
+
+
+
+ {/if}
{if isset($birthday) && $birthday}
+ {if isset($nationality) && $nationality}
+
+ {l s='Nationality'}{if isset($nationality_mandatory) && $nationality_mandatory} *{/if}
+
+
+ {/if}
+ {if isset($nationality) && $nationality}
+
+
+ {l s='Nationality'}{if isset($nationality_mandatory) && $nationality_mandatory} *{/if}
+
+
+
+ {/if}
{if isset($PS_REGISTRATION_PROCESS_TYPE) && $PS_REGISTRATION_PROCESS_TYPE}
{if isset($birthday) && $birthday}