0
我正在使用Prestashop 1.7,並且正在開發用於學習目的的EAN13生成器模塊。 我很難用配置函數更新數據庫的值,因爲它重新加載頁面,但不更新任何內容。Prestashop - 配置頁面不更新DB值
我想用表單設置'C_CODE'和'B_CODE'的值來爲產品生成EAN13。 下面是調用函數的代碼:
public function getContent() {
return $this->renderForm().$this->postForm();
}
public function postForm() {
if (Tools::isSubmit('submitConf')) { //Cambiamos valores
Configuration::updateValue('C_CODE', Tools::getValue('C_CODE_'));
Configuration::updateValue('B_CODE', Tools::getValue('B_CODE_'));
return $this->displayConfirmation($this->l('Settings changed'));
}
return '';
}
這些都是我的「renderForm」。我認爲是'currentIndex'的問題,但我無法解決它。
public function renderForm() {
// Get default language
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
// Init fields from an array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Configuración del EAN'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Código del país'),
'name' => 'C_CODE',
'size' => 10,
'required' => true
),
array(
'type' => 'text',
'label' => $this->l('Código de la empresa'),
'name' => 'B_CODE',
'size' => 20,
'required' => true
)
),
'submit' => array(
'title' => $this->l('Generar EAN13'),
'class' => 'btn btn-default pull-center'
)
);
$helper = new HelperForm();
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// title and Toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submitConf';
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
$helper->fields_value['C_CODE'] = Configuration::get('C_CODE');
$helper->fields_value['B_CODE'] = Configuration::get('B_CODE');
//TODO: Fill with toolbars and more options
return $helper->generateForm($fields_form);
}
非常感謝您的支持!
我在renderForm()之前複製了postForm()並且它工作。我的意思是我已經複製了函數的內容。我的意思是,prestashop的很多模塊在postForm()之前調用renderForm(),所以我正在觀察該方法。非常感謝你的回答,作品非常好! –