Наконец я нашел решение.Сначала я устанавливаю новую таблицу с помощью этого кода:
$sql = array();
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'fattura24` (
`id_fattura24` int(11) NOT NULL AUTO_INCREMENT,
`id_customer` int(11),
`fattura24_codice_destinatario` varchar(13),
`fattura24_pec` varchar(60),
PRIMARY KEY (`id_fattura24`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
foreach ($sql as $query) {
if (Db::getInstance()->execute($query) == false) {
return false;
}
}
Затем я создаю хук и шаблон для каждого действия, в котором я хочу отобразить поля.В примере вы увидите DisplayCustomerIdentityForm:
public function hookDisplayCustomerIdentityForm($params){
$sdi_code = Tools::getValue('fattura24_codice_destinatario');
if (!$sdi_code or strlen($sdi_code) <= 1)
{
$sdi_code = '0000000';
}
if (Tools::getValue('id_fattura24')>0)
{
$sql = "update `"._DB_PREFIX_."fattura24` set fattura24_codice_destinatario = '".pSQL($sdi_code)."',fattura24_pec='".pSQL(Tools::getValue('fattura24_pec'))."'
where id_fattura24 = ".(int)Tools::getValue('id_fattura24')." ";
Db::getInstance()->Execute($sql);
} elseif (Tools::getValue('fattura24_id_customer')) {
$sql = "INSERT INTO `"._DB_PREFIX_."fattura24`(id_customer,fattura24_codice_destinatario,fattura24_pec)
VALUES (".pSQL(Tools::getValue('fattura24_id_customer')).",'".pSQL($sdi_code)."','".pSQL(Tools::getValue('fattura24_pec'))."')";
Db::getInstance()->Execute($sql);
}
if ($params['cookie']->id_customer)
{
$sql = "select id_fattura24,fattura24_codice_destinatario,fattura24_pec from `"._DB_PREFIX_."fattura24` where id_customer = ".$params['cookie']->id_customer."";
$result = Db::getInstance()->getRow($sql);
}
$this->context->smarty->assign('id_fattura24', $result['id_fattura24']);
$this->context->smarty->assign('fattura24_id_customer', $params['cookie']->id_customer);
$this->context->smarty->assign('fattura24_codice_destinatario', $result['fattura24_codice_destinatario']);
$this->context->smarty->assign('fattura24_pec', $result['fattura24_pec']);
return $this->display(__FILE__, 'views/templates/hook/customer_reg_form.tpl');
}
Помните, что вы должны зарегистрировать ловушку:
if (!parent::install()
. . .
|| !$this->registerHook('displayCustomerIdentityForm')
. . .
return false;
В конце концов, давайте покажем customer_reg_form.tpl:
<input type="hidden" name="id_fattura24" value="{if isset($id_fattura24)}{$id_fattura24}{else}{/if}">
<input type="hidden" name="fattura24_id_customer" value="{$fattura24_id_customer}">
<div class="form-group row">
<label>{l s='Indirizzo PEC' mod='fattura24'}</label>
<div>
<input type="email" name="fattura24_pec" value="{if isset($smarty.post.fattura24_pec)}{$smarty.post.fattura24_pec}{else}{$fattura24_pec}{/if}"/>
</div>
</div>
<div class="form-group row">
<label>{l s='Codice Destinatario' mod='fattura24'}</label>
<div>
<input type="text" maxlength="7" name="fattura24_codice_destinatario" value="{if isset($smarty.post.fattura24_codice_destinatario)}{$smarty.post.fattura24_codice_destinatario}{else}{$fattura24_codice_destinatario}{/if}"/>
</div>
</div>