prestashop - Very basic "creating your first module" tutorial fail. How? -
so i'm following prestashop's published hand-holding guide (which references helper classes), isn't working.
since other "how make module" questions point there, i'm getting fast.
at bottom of question code i'm @ far , don't particular error, i'm not seeing * promised beside required field. when add
'desc' => $this->l('description displayed under field.'),
it goes left, not under, , if add
'lang' => true,
i lose input entirely.
that's copy pasted out of guides, missing? unfortunately isn't complete document. should have complete working example. now, there reference vaguely template file (tpl) far point isn't explicitly mentioned. @ point have single php file indicated point in tutorial.
<?php if (!defined('_ps_version_')) exit; class spfishbox extends module { public function __construct() { $this->name = 'spfishbox'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'sp'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _ps_version_); $this->bootstrap = false; parent::__construct(); $this->displayname = $this->l('fishbox'); $this->description = $this->l('adds fishbox code snipped.'); $this->confirmuninstall = $this->l('are sure want uninstall?'); if (!configuration::get('mymodule_name')) $this->warning = $this->l('no name provided'); } public function install() { if (shop::isfeatureactive()) shop::setcontext(shop::context_all); if (!parent::install() || !$this->registerhook('header') || !configuration::updatevalue('mymodule_name', 'fishbox snippet') ) return false; return true; } public function uninstall() { if (!parent::uninstall()) return false; return true; } public function getcontent() { $output = null; if (tools::issubmit('submit'.$this->name)) { $my_module_name = strval(tools::getvalue('mymodule_name')); if (!$my_module_name || empty($my_module_name) || !validate::isgenericname($my_module_name)) $output .= $this->displayerror($this->l('invalid configuration value')); else { configuration::updatevalue('mymodule_name', $my_module_name); $output .= $this->displayconfirmation($this->l('settings updated')); } } return $output.$this->displayform(); } public function displayform() { // default language $default_lang = (int)configuration::get('ps_lang_default'); // init fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('configuration value'), 'name' => 'mymodule_name', 'size' => 20, 'required' => true ) ), 'submit' => array( 'title' => $this->l('save'), 'class' => 'button' ) ); $helper = new helperform(); // module, token , currentindex $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 , toolbar $helper->title = $this->displayname; $helper->show_toolbar = true; // false -> remove toolbar $helper->toolbar_scroll = true; // yes - > toolbar visible on top of screen. $helper->submit_action = 'submit'.$this->name; $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 list') ) ); // load current value $helper->fields_value['mymodule_name'] = configuration::get('mymodule_name'); return $helper->generateform($fields_form); } }
you have following modifications:
$this->bootstrap = true;
and:
$languages = language::getlanguages(false); foreach ($languages $k => $language) $languages[$k]['is_default'] = (int)$language['id_lang'] == configuration::get('ps_lang_default'); $helper->languages = $languages;
full code:
<?php if (!defined('_ps_version_')) exit; class spfishbox extends module { public function __construct() { $this->name = 'spfishbox'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'sp'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _ps_version_); $this->bootstrap = true; parent::__construct(); $this->displayname = $this->l('fishbox'); $this->description = $this->l('adds fishbox code snipped.'); $this->confirmuninstall = $this->l('are sure want uninstall?'); if (!configuration::get('mymodule_name')) $this->warning = $this->l('no name provided'); } public function install() { if (shop::isfeatureactive()) shop::setcontext(shop::context_all); if (!parent::install() || !$this->registerhook('header') || !configuration::updatevalue('mymodule_name', 'fishbox snippet') ) return false; return true; } public function uninstall() { if (!parent::uninstall()) return false; return true; } public function getcontent() { $output = null; if (tools::issubmit('submit'.$this->name)) { $my_module_name = strval(tools::getvalue('mymodule_name')); if (!$my_module_name || empty($my_module_name) || !validate::isgenericname($my_module_name)) $output .= $this->displayerror($this->l('invalid configuration value')); else { configuration::updatevalue('mymodule_name', $my_module_name); $output .= $this->displayconfirmation($this->l('settings updated')); } } return $output.$this->displayform(); } public function displayform() { // default language $default_lang = (int)configuration::get('ps_lang_default'); // init fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('configuration value'), 'name' => 'mymodule_name', 'size' => 20, 'required' => true, 'desc' => $this->l('description displayed under field.'), 'lang' => true, ) ), 'submit' => array( 'title' => $this->l('save'), 'class' => 'button' ) ); $helper = new helperform(); $languages = language::getlanguages(false); foreach ($languages $k => $language) $languages[$k]['is_default'] = (int)$language['id_lang'] == configuration::get('ps_lang_default'); $helper->languages = $languages; // module, token , currentindex $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 , toolbar $helper->title = $this->displayname; $helper->show_toolbar = true; // false -> remove toolbar $helper->toolbar_scroll = true; // yes - > toolbar visible on top of screen. $helper->submit_action = 'submit'.$this->name; $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 list') ) ); // load current value $helper->fields_value['mymodule_name'] = configuration::get('mymodule_name'); return $helper->generateform($fields_form); } }
Comments
Post a Comment