Hi,
why my module don't save data to sql?
Field is visible on sql..
My code module:
<?php /* * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) { exit; } use PrestaShop\PrestaShop\Core\Module\WidgetInterface; use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Validation; class Ps_Customfields extends Module implements WidgetInterface { private $templateFile; const BLOCK_CUSTOM = [ 'toptext', ]; public function __construct() { $this->name = 'ps_customfields'; $this->author = 'Intermedia'; $this->version = '1.0.0'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->trans('Custom fields', array(), 'Modules.Customfields.Admin'); $this->description = $this->trans('Custom fields for theme.', array(), 'Modules.Customfields.Admin'); $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); $this->templateFile = 'module:ps_customfields/ps_customfields.tpl'; } public function install() { return (parent::install() && Configuration::updateValue('BLOCKCUSTOM_TOPTEXT', '') && $this->registerHook('displayFooter')); } public function uninstall() { return (Configuration::deleteByName('BLOCKCUSTOM_TOPTEXT') && parent::uninstall()); } public function getContent() { if (Tools::isSubmit('submitModule')) { $this->updateFields(); $this->_clearCache('*'); Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&tab_module='.$this->tab.'&conf=4&module_name='.$this->name); } return $this->renderForm(); } public function _clearCache($template, $cache_id = null, $compile_id = null) { parent::_clearCache($this->templateFile); } public function renderForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->trans('Settings', array(), 'Admin.Global'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->trans('Top Text', array(), 'Modules.Customfields.Admin'), 'name' => 'blockcustom_toptext', ), ), 'submit' => array( 'title' => $this->trans('Save', array(), 'Admin.Global'), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->submit_action = 'submitModule'; $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValues(), ); return $helper->generateForm(array($fields_form)); } public function getConfigFieldsValues() { $result = []; foreach (static::BLOCK_CUSTOM as $custom) { $result['blockcustom_' . $custom] = Configuration::get('BLOCKCUSTOM_' . strtoupper($custom)); } return $result; } public function renderWidget($hookName = null, array $configuration = []) { if (!$this->isCached($this->templateFile, $this->getCacheId('ps_customfields'))) { $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); } return $this->fetch($this->templateFile, $this->getCacheId('ps_customfields')); } public function getWidgetVariables($hookName = null, array $configuration = []) { $block_custom = array(); if ($sf_toptext = Configuration::get('BLOCKCUSTOM_TOPTEXT')) { $block_custom['toptext'] = array( 'label' => $this->trans('Top Text', array(), 'Modules.Customfields.Shop'), 'class' => 'toptext', 'url' => $sf_toptext, ); } return array( 'social_links' => $block_custom, ); } protected function updateFields() { $validator = Validation::createValidator(); $constraints = [new Url()]; foreach (static::BLOCK_CUSTOM as $custom) { $value = Tools::getValue('blockcustom_' . $custom, ''); $violations = $validator->validate($value, $constraints); if (0 === count($violations)) { Configuration::updateValue('BLOCKCUSTOM_' . strtoupper($custom), $value); } } } }