2017-03-07 91 views
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); 

} 

非常感谢您的支持!

回答

0

getContent()方法中,您需要以相反顺序调用窗体方法。

您需要先保存配置值,然后再显示表格。

public function getContent() { 
    return $this->postForm().$this->renderForm(); 
} 
+0

我在renderForm()之前复制了postForm()并且它工作。我的意思是我已经复制了函数的内容。我的意思是,prestashop的很多模块在postForm()之前调用renderForm(),所以我正在观察该方法。非常感谢你的回答,作品非常好! –