Añadir campos al backoffice
<?php
function renderForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Contact details'),
'icon' => 'icon-envelope',
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Account owner'),
'name' => 'BANK_WIRE_OWNER',
'required' => true,
),
array(
'type' => 'textarea',
'label' => $this->l('Details'),
'name' => 'BANK_WIRE_DETAILS',
'desc' => $this->l('Such as bank branch, IBAN number, BIC, etc.'),
'required' => true,
),
array(
'type' => 'textarea',
'label' => $this->l('Bank address'),
'name' => 'BANK_WIRE_ADDRESS',
'required' => true,
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->id = (int) Tools::getValue('id_carrier');
$helper->identifier = $this->identifier;
$helper->submit_action = 'btnSubmit';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($fields_form));
}
function hookActionAdminStoresFormModifier($params)
{
$idStore = Tools::getValue('id_store', 0);
if ($idStore != 0) {
$sql = 'SELECT tipo FROM ' . _DB_PREFIX_ . 'storestipo where id_store = ' . $idStore;
$result = Db::getInstance()->getValue($sql);
$select = array(
1 => array('id_tipoStore' => 1, 'nombre' => 'Distribuidor'),
2 => array('id_tipoStore' => 2, 'nombre' => 'Punto de Venta'),
);
$params['fields'][0]['form']['input'][] = array(
'type' => 'select',
'label' => $this->l('Tipo de Tienda'),
'name' => 'tipoStore',
'required' => true,
'default_value' => 1,
'options' => array(
'query' => $select,
'id' => 'id_tipoStore',
'name' => 'nombre',
),
);
$params['fields_value']['tipoStore'] = $result;
}
}
function hookActionObjectStoreAddAfter($params)
{
$tipoStore = Tools::getValue('tipoStore');
if ($tipoStore) {
$idStore = $params['object']->id;
if ($idStore) {
$sql = 'INSERT IGNORE INTO ' . _DB_PREFIX_ . 'storestipo (id_store, tipo) VALUES (' . $idStore . ',' . $tipoStore . ')';
Db::getInstance()->execute($sql);
}
}
}
function hookActionObjectStoreUpdateAfter($params)
{
$tipoStore = Tools::getValue('tipoStore');
if ($tipoStore) {
$idStore = $params['object']->id;
if ($idStore) {
$sql = 'UPDATE ' . _DB_PREFIX_ . 'storestipo SET tipo=' . $tipoStore . ' WHERE id_store=' . $idStore;
Db::getInstance()->execute($sql);
}
}
}
function hookActionAdminStoresListingResultsModifier($params)
{
foreach ($params['list'] as &$elemento) {
if (isset($elemento['id_store']) && !empty($elemento['id_store'])) {
$sql = 'SELECT tipo FROM ' . _DB_PREFIX_ . 'storestipo where id_store = ' . $elemento['id_store'];
$result = Db::getInstance()->getValue($sql);
if ($result == 1) {
$elemento['tipoStore'] = 'Distribuidor';
} else if ($result == 2) {
$elemento['tipoStore'] = 'Punto de Venta';
} else {
$elemento['tipoStore'] = ' -- ';
}
}
}
}
function hookActionAdminStoresListingFieldsModifier($params)
{
$params['fields']['tipoStore'] = array();
$params['fields']['tipoStore']['title'] = $this->l('Tipo Store');
$params['fields']['tipoStore']['orderby'] = false;
$params['fields']['tipoStore']['search'] = false;
$params['fields']['tipoStore']['align'] = 'center';
}