php - Save (and retrieve) module configurations in Prestashop -
good day all. have simple module on prestashop, i'd add configuration flag, boolean value user can enable/disable configure module. easy. i've done "vikings" way, using form in tpl , read php post variables.
but i'd in proper way.
what i've far form, created in module:
protected function getconfigform() { return array( 'form' => array( 'legend' => array( 'title' => $this->l('settings'), 'icon' => 'icon-cogs', ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('a label'), 'name' => 'multishop_language_mode', 'is_bool' => true, 'desc' => $this->l('use language on every shop'), 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('disabled') ) ) ) ), 'submit' => array( 'title' => $this->l('save'), ), ), ); }
then got functions set , values:
protected function getconfigformvalues() { return array( 'multishop_language_mode' => configuration::get('multishop_language_mode', true) ); } /** * save form data. */ protected function postprocess() { configuration::updatevalue('multishop_language_mode', tools::getvalue('multishop_language_mode')); }
i'm forgetting something? because switch on form, never change, everytime reload form, switch on "false".
the db never change after submitting (saving) form.
thanks in advance.
update: db change, when submitting form, value of field become null
i've managed solve issue, don't know why, writing function in way makes works charm.
protected function getconfigformvalues() { return array( 'hreflangforprestashop_multishop_language_mode' => configuration::get('hreflangforprestashop_multishop_language_mode') ); }
note, i've deleted second parameter of return array, true
Comments
Post a Comment