<?php
class AdminAddressesController extends AdminAddressesControllerCore
{
public function renderForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->trans('Addresses', array(), 'Admin.Orderscustomers.Feature'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text_customer',
'label' => $this->trans('Customer', array(), 'Admin.Global'),
'name' => 'id_customer',
'required' => false,
),
array(
'type' => 'text',
'label' => $this->trans('Identification number', array(), 'Admin.Orderscustomers.Feature'),
'name' => 'dni',
'required' => false,
'col' => '4',
'hint' => $this->trans('The national ID card number of this person, or a unique tax identification number.', array(), 'Admin.Orderscustomers.Feature')
),
array(
'type' => 'text',
'label' => $this->trans('Address alias', array(), 'Admin.Orderscustomers.Feature'),
'name' => 'alias',
'required' => true,
'col' => '4',
'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' <>;=#{}'
),
array(
'type' => 'textarea',
'label' => $this->trans('Other', array(), 'Admin.Global'),
'name' => 'other',
'required' => false,
'cols' => 15,
'rows' => 3,
'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' <>;=#{}'
),
array(
'type' => 'hidden',
'name' => 'id_order'
),
array(
'type' => 'hidden',
'name' => 'address_type',
),
array(
'type' => 'hidden',
'name' => 'back'
)
),
'submit' => array(
'title' => $this->trans('Save', array(), 'Admin.Actions'),
)
);
$this->fields_value['address_type'] = (int)Tools::getValue('address_type', 1);
$id_customer = (int)Tools::getValue('id_customer');
if (!$id_customer && Validate::isLoadedObject($this->object)) {
$id_customer = $this->object->id_customer;
}
if ($id_customer) {
$customer = new Customer((int)$id_customer);
$token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id);
}
$this->tpl_form_vars = array(
'customer' => isset($customer) ? $customer : null,
'tokenCustomer' => isset($token_customer) ? $token_customer : null,
'back_url' => urldecode(Tools::getValue('back'))
);
// Order address fields depending on country format
$addresses_fields = $this->processAddressFormat();
// we use delivery address
$addresses_fields = $addresses_fields['dlv_all_fields'];
// get required field
$required_fields = AddressFormat::getFieldsRequired();
// Merge with field required
$addresses_fields = array_unique(array_merge($addresses_fields, $required_fields));
$temp_fields = array();
foreach ($addresses_fields as $addr_field_item) {
if ($addr_field_item == 'company') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Company', array(), 'Admin.Global'),
'name' => 'company',
'required' => in_array('company', $required_fields),
'col' => '4',
'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' <>;=#{}'
);
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('VAT number', array(), 'Admin.Orderscustomers.Feature'),
'col' => '2',
'name' => 'vat_number',
'required' => in_array('vat_number', $required_fields)
);
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Sdi', array(), 'Admin.Orderscustomers.Feature'),
'col' => '2',
'name' => 'sdi',
'required' => false
);
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Pec', array(), 'Admin.Orderscustomers.Feature'),
'col' => '2',
'name' => 'pec',
'required' => false
);
} elseif ($addr_field_item == 'lastname') {
if (isset($customer) &&
!Tools::isSubmit('submit'.strtoupper($this->table)) &&
Validate::isLoadedObject($customer) &&
!Validate::isLoadedObject($this->object)) {
$default_value = $customer->lastname;
} else {
$default_value = '';
}
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Last Name', array(), 'Admin.Global'),
'name' => 'lastname',
'required' => true,
'col' => '4',
'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' 0-9!&lt;&gt;,;?=+()@#"�{}_$%:',
'default_value' => $default_value,
);
} elseif ($addr_field_item == 'firstname') {
if (isset($customer) &&
!Tools::isSubmit('submit'.strtoupper($this->table)) &&
Validate::isLoadedObject($customer) &&
!Validate::isLoadedObject($this->object)) {
$default_value = $customer->firstname;
} else {
$default_value = '';
}
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('First Name', array(), 'Admin.Global'),
'name' => 'firstname',
'required' => true,
'col' => '4',
'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' 0-9!&lt;&gt;,;?=+()@#"�{}_$%:',
'default_value' => $default_value,
);
} elseif ($addr_field_item == 'address1') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Address', array(), 'Admin.Global'),
'name' => 'address1',
'col' => '6',
'required' => true,
);
} elseif ($addr_field_item == 'address2') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Address', array(), 'Admin.Global').' (2)',
'name' => 'address2',
'col' => '6',
'required' => in_array('address2', $required_fields),
);
} elseif ($addr_field_item == 'postcode') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Zip/postal code', array(), 'Admin.Global'),
'name' => 'postcode',
'col' => '2',
'required' => true,
);
} elseif ($addr_field_item == 'city') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('City', array(), 'Admin.Global'),
'name' => 'city',
'col' => '4',
'required' => true,
);
} elseif ($addr_field_item == 'country' || $addr_field_item == 'Country:name') {
$temp_fields[] = array(
'type' => 'select',
'label' => $this->trans('Country', array(), 'Admin.Global'),
'name' => 'id_country',
'required' => in_array('Country:name', $required_fields) || in_array('country', $required_fields),
'col' => '4',
'default_value' => (int)$this->context->country->id,
'options' => array(
'query' => Country::getCountries($this->context->language->id),
'id' => 'id_country',
'name' => 'name'
)
);
$temp_fields[] = array(
'type' => 'select',
'label' => $this->trans('State', array(), 'Admin.Global'),
'name' => 'id_state',
'required' => false,
'col' => '4',
'options' => array(
'query' => array(),
'id' => 'id_state',
'name' => 'name'
)
);
} elseif ($addr_field_item == 'phone') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Home phone', array(), 'Admin.Global'),
'name' => 'phone',
'required' => in_array('phone', $required_fields),
'col' => '4',
);
} elseif ($addr_field_item == 'phone_mobile') {
$temp_fields[] = array(
'type' => 'text',
'label' => $this->trans('Mobile phone', array(), 'Admin.Global'),
'name' => 'phone_mobile',
'required' => in_array('phone_mobile', $required_fields),
'col' => '4',
);
}
}
// merge address format with the rest of the form
array_splice($this->fields_form['input'], 3, 0, $temp_fields);
return AdminController::renderForm();
//return parent::renderForm();
}
}