// fix states selection in form and address format in AdminAddress
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9309 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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});
|
||||
</script>
|
||||
<script type="text/javascript" src="../js/form.js"></script>
|
||||
@@ -94,6 +92,7 @@
|
||||
{/foreach}
|
||||
{else}
|
||||
{foreach $input.options.query AS $option}
|
||||
{$fields_value[$input.name]|@p}
|
||||
<option value="{$option[$input.options.id]}"
|
||||
{if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}>{$option[$input.options.name]}</option>
|
||||
{/foreach}
|
||||
|
||||
@@ -575,6 +575,7 @@ class AdminControllerCore extends Controller
|
||||
|
||||
/**
|
||||
* Display form
|
||||
* TODO to be removed
|
||||
*/
|
||||
public function displayForm($firstCall = true)
|
||||
{
|
||||
|
||||
@@ -94,86 +94,6 @@ class AdminAddressesControllerCore extends AdminController
|
||||
'required' => true,
|
||||
'p' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('First name'),
|
||||
'name' => 'firstname',
|
||||
'size' => 33,
|
||||
'required' => true,
|
||||
'p' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Last name'),
|
||||
'name' => 'lastname',
|
||||
'size' => 33,
|
||||
'required' => true,
|
||||
'p' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Company'),
|
||||
'name' => 'company',
|
||||
'size' => 33,
|
||||
'required' => false,
|
||||
'p' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>'
|
||||
),
|
||||
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' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>'
|
||||
);
|
||||
$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' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>'
|
||||
);
|
||||
}
|
||||
elseif ($addr_field_item == 'firstname')
|
||||
{
|
||||
$temp_fields[] = array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('First name'),
|
||||
'name' => 'firstname',
|
||||
'size' => 33,
|
||||
'required' => true,
|
||||
'p' => '<span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>'
|
||||
);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user