diff --git a/admin-dev/themes/template/addresses/form.tpl b/admin-dev/themes/template/addresses/form.tpl
index 232038379..cb4c99104 100644
--- a/admin-dev/themes/template/addresses/form.tpl
+++ b/admin-dev/themes/template/addresses/form.tpl
@@ -40,16 +40,14 @@
{rdelim};
{/foreach}
displayFlags(languages, id_language, {$allowEmployeeFormLang});
-
- {literal}
+
if ($('#id_country'))
- {
- ajaxStates();
- $('#id_country').change(function() {
+ {ldelim}
+ ajaxStates({$fields_value.id_state});
+ $('#id_country').change(function() {ldelim}
ajaxStates();
- });
- }
- {/literal}
+ {rdelim});
+ {rdelim}
{rdelim});
{if isset($script)}
{$script}
diff --git a/admin-dev/themes/template/form.tpl b/admin-dev/themes/template/form.tpl
index 589389234..06b299b47 100644
--- a/admin-dev/themes/template/form.tpl
+++ b/admin-dev/themes/template/form.tpl
@@ -41,15 +41,13 @@
{/foreach}
displayFlags(languages, id_language, {$allowEmployeeFormLang});
- {literal}
if ($('#id_country') && $('#id_state'))
- {
- ajaxStates();
- $('#id_country').change(function() {
+ {ldelim}
+ ajaxStates({$fields_value.id_state});
+ $('#id_country').change(function() {ldelim}
ajaxStates();
- });
- }
- {/literal}
+ {rdelim});
+ {rdelim}
{rdelim});
@@ -94,6 +92,7 @@
{/foreach}
{else}
{foreach $input.options.query AS $option}
+ {$fields_value[$input.name]|@p}
{/foreach}
diff --git a/classes/AdminController.php b/classes/AdminController.php
index e720ed021..611f4546f 100644
--- a/classes/AdminController.php
+++ b/classes/AdminController.php
@@ -575,6 +575,7 @@ class AdminControllerCore extends Controller
/**
* Display form
+ * TODO to be removed
*/
public function displayForm($firstCall = true)
{
diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php
index 9834a5104..57074c156 100644
--- a/controllers/admin/AdminAddressesController.php
+++ b/controllers/admin/AdminAddressesController.php
@@ -94,86 +94,6 @@ class AdminAddressesControllerCore extends AdminController
'required' => true,
'p' => ''.$this->l('Invalid characters:').' <>;=#{} '
),
- array(
- 'type' => 'text',
- 'label' => $this->l('First name'),
- 'name' => 'firstname',
- 'size' => 33,
- 'required' => true,
- 'p' => ''.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: '
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('Last name'),
- 'name' => 'lastname',
- 'size' => 33,
- 'required' => true,
- 'p' => ''.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: '
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('Company'),
- 'name' => 'company',
- 'size' => 33,
- 'required' => false,
- 'p' => ''.$this->l('Invalid characters:').' <>;=#{} '
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('VAT number'),
- 'name' => 'vat_number',
- 'size' => 33,
- ''
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('Address'),
- 'name' => 'address1',
- 'size' => 33,
- 'required' => true,
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('Address').' (2)',
- 'name' => 'address2',
- 'size' => 33,
- 'required' => false,
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('Postcode/ Zip Code'),
- 'name' => 'postcode',
- 'size' => 33,
- 'required' => false,
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('City'),
- 'name' => 'city',
- 'size' => 33,
- 'required' => true,
- ),
- array(
- 'type' => 'select',
- 'label' => $this->l('Country:'),
- 'name' => 'id_country',
- 'required' => false,
- 'options' => array(
- 'query' => Country::getCountries($this->context->language->id),
- 'id' => 'id_country',
- 'name' => 'name'
- ),
- ),
- array(
- 'type' => 'select',
- 'label' => $this->l('State'),
- 'name' => 'id_state',
- 'required' => false,
- 'options' => array(
- 'id' => 'id_state',
- 'name' => 'name'
- ),
- ),
array(
'type' => 'text',
'label' => $this->l('Home phone'),
@@ -550,29 +470,149 @@ class AdminAddressesControllerCore extends AdminController
public function initContent()
{
- if ($this->display != 'edit' && $this->display != 'add')
+ if ($this->display == 'edit' || $this->display == 'add')
+ {
+ if (!($address = $this->loadObject(true)))
+ return false;
+
+ if (Validate::isLoadedObject($address))
+ {
+ $customer = new Customer($address->id_customer);
+ $tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id);
+ }
+
+ if (Configuration::get('VATNUMBER_MANAGEMENT'))
+ if (file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php') && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT')))
+ $vat = 'is_applicable';
+ else
+ $vat = 'management';
+
+ $this->context->smarty->assign(array(
+ 'vat' => isset($vat) ? $vat : null,
+ 'customer' => isset($customer) ? $customer : null,
+ 'tokenCustomer' => isset ($tokenCustomer) ? $tokenCustomer : null
+ ));
+
+ // Order address fields depending on country norm
+ $addresses_fields = $this->processAddressFormat();
+ $addresses_fields = $addresses_fields["dlv_all_fields"]; // we use delivery address
+
+ $temp_fields = array();
+
+ foreach($addresses_fields as $addr_field_item)
+ {
+ if ($addr_field_item == 'company')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('Company'),
+ 'name' => 'company',
+ 'size' => 33,
+ 'required' => false,
+ 'p' => ''.$this->l('Invalid characters:').' <>;=#{} '
+ );
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('VAT number'),
+ 'name' => 'vat_number',
+ 'size' => 33,
+ ''
+ );
+ }
+ elseif ($addr_field_item == 'lastname')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('Last name'),
+ 'name' => 'lastname',
+ 'size' => 33,
+ 'required' => true,
+ 'p' => ''.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: '
+ );
+ }
+ elseif ($addr_field_item == 'firstname')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('First name'),
+ 'name' => 'firstname',
+ 'size' => 33,
+ 'required' => true,
+ 'p' => ''.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: '
+ );
+ }
+ elseif ($addr_field_item == 'address1')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('Address'),
+ 'name' => 'address1',
+ 'size' => 33,
+ 'required' => true,
+ );
+ }
+ elseif ($addr_field_item == 'address2')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('Address').' (2)',
+ 'name' => 'address2',
+ 'size' => 33,
+ 'required' => false,
+ );
+ }
+ elseif ($addr_field_item == 'postcode')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('Postcode/ Zip Code'),
+ 'name' => 'postcode',
+ 'size' => 33,
+ 'required' => false,
+ );
+ }
+ elseif ($addr_field_item == 'city')
+ {
+ $temp_fields[] = array(
+ 'type' => 'text',
+ 'label' => $this->l('City'),
+ 'name' => 'city',
+ 'size' => 33,
+ 'required' => true,
+ );
+ }
+ elseif ($addr_field_item == 'country' || $addr_field_item == 'Country:name')
+ {
+ $temp_fields[] = array(
+ 'type' => 'select',
+ 'label' => $this->l('Country:'),
+ 'name' => 'id_country',
+ 'required' => false,
+ 'options' => array(
+ 'query' => Country::getCountries($this->context->language->id),
+ 'id' => 'id_country',
+ 'name' => 'name'
+ )
+ );
+ $temp_fields[] = array(
+ 'type' => 'select',
+ 'label' => $this->l('State'),
+ 'name' => 'id_state',
+ 'required' => false,
+ 'options' => array(
+ 'id' => 'id_state',
+ 'name' => 'name'
+ )
+ );
+
+ }
+ }
+ // merge address format with the rest of the form
+ array_splice($this->fields_form['input'], 3, 0, $temp_fields);
+ }
+ else
$this->display = 'list';
- if (!($address = $this->loadObject(true)))
- return false;
-
- if (Validate::isLoadedObject($address))
- {
- $customer = new Customer($address->id_customer);
- $tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id);
- }
-
- if (Configuration::get('VATNUMBER_MANAGEMENT'))
- if (file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php') && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT')))
- $vat = 'is_applicable';
- else
- $vat = 'management';
-
- $this->context->smarty->assign(array(
- 'vat' => isset($vat) ? $vat : null,
- 'customer' => isset($customer) ? $customer : null,
- 'tokenCustomer' => isset ($tokenCustomer) ? $tokenCustomer : null
- ));
parent::initContent();
}
diff --git a/js/form.js b/js/form.js
index ab6579a14..d93d826f6 100644
--- a/js/form.js
+++ b/js/form.js
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
-function ajaxStates ()
+function ajaxStates (id_state_selected)
{
$.ajax({
url: "ajax.php",
@@ -41,7 +41,7 @@ function ajaxStates ()
{
$("#id_state").html(html);
$("#contains_states").fadeIn();
- $('#id_state option[value={$obj->id_state}]').attr("selected", "selected");
+ $('#id_state option[value=' + id_state_selected + ']').attr("selected", "selected");
}
}
});