SIWA_Fabian Posted June 23, 2020 Share Posted June 23, 2020 Hey guys! I just created a module and it works fine, but as soon as i turn on the debug mode following errors show up: Notice in Zeile 801 der Datei /Applications/MAMP/htdocs/var/cache/dev/smarty/compile/db/56/74/db567485f5fc1b76e32f03a400289021d1354998_0.file.form.tpl.php [8] Undefined index: SIWA_ORDEREXPORT_STATES Notice in Zeile 1384 der Datei /Applications/MAMP/htdocs/var/cache/dev/smarty/compile/db/56/74/db567485f5fc1b76e32f03a400289021d1354998_0.file.form.tpl.php [8] Undefined index: SIWA_ORDERDATE_START Notice in Zeile 1384 der Datei /Applications/MAMP/htdocs/var/cache/dev/smarty/compile/db/56/74/db567485f5fc1b76e32f03a400289021d1354998_0.file.form.tpl.php [8] Undefined index: SIWA_ORDERDATE_END The first one is repeated 13 times. One for each order status existing in the shop. As far as i beliefe now. This is basically the code which uses said variables but i can't find where i made my mistake: (Probably its quite obvious. 😅 ) const CONF_SIWA_ORDEREXPORT_STATES = 'SIWA_ORDEREXPORT_STATES'; const CONF_SIWA_ORDERDATE_START = 'SIWA_ORDERDATE_START'; const CONF_SIWA_ORDERDATE_END = 'SIWA_ORDERDATE_END'; public function getContent() { $output = ''; if (Tools::isSubmit('submit'.$this->name)) { Configuration::updateValue( self::CONF_SIWA_ORDEREXPORT_STATES, Tools::getValue(self::CONF_SIWA_ORDEREXPORT_STATES) ); downloadCSV( Configuration::get(self::CONF_SIWA_ORDEREXPORT_STATES), Tools::getValue(self::CONF_SIWA_ORDERDATE_START), Tools::getValue(self::CONF_SIWA_ORDERDATE_END), $this->headerNames ); $output = $this->displayConfirmation( $this->trans( 'Settings updated', array(), "Modules.Orderdownload.Admin" ) ); } $defaultLang = (int)Configuration::get('PS_LANG_DEFAULT'); $orderStates = OrderState::getOrderStates($this->context->language->id); $fieldsForm = array(); $fieldsForm[0] = array(); $fieldsForm[0]['form'] = [ 'legend' => [ 'title' => $this->trans('Settings', array(), "Modules.Orderdownload.Admin"), ], 'input' => [ [ 'type' => 'select', 'label' => $this->trans('Orderstatus', array(), "Modules.Orderdownload.Admin"), 'name' => self::CONF_SIWA_ORDEREXPORT_STATES, 'required' => true, 'multiple' => false, 'options' => array( 'query' => $orderStates, // $options contains the data itself. 'id' => 'id_order_state', // The value of the 'id' key //must be the same as the key for 'value' //attribute of the <option> tag in each $options sub-array. 'name' => 'name' // The value of the 'name' key //must be the same as the key for the text //content of the <option> tag in each $options sub-array. ) ], [ 'type' => 'date', 'label' => $this->trans('Startdate', array(), "Modules.Orderdownload.Admin"), 'name' => self::CONF_SIWA_ORDERDATE_START, 'required' => true ], [ 'type' => 'date', 'label' => $this->trans('Enddate', array(), "Modules.Orderdownload.Admin"), 'name' => self::CONF_SIWA_ORDERDATE_END, 'required' => true ] ], 'submit' => [ 'title' => $this->trans('Save', array(), "Modules.Orderdownload.Admin"), 'class' => 'btn btn-default pull-right' ] ]; $helper = new HelperForm(); // Module, token and 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 = $defaultLang; $helper->allow_employee_form_lang = $defaultLang; // Title and toolbar $helper->title = $this->displayName; $helper->show_toolbar = false; $helper->submit_action = 'submit'.$this->name; $helper->toolbar_btn = [ 'save' => [ 'desc' => $this->trans('Save', array(), "Modules.Orderdownload.Admin"), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. '&token='.Tools::getAdminTokenLite('AdminModules'), ], 'back' => [ 'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->trans('Back to list', array(), "Modules.Orderdownload.Admin") ] ]; // Load current value $helper->fields_value = array_merge($helper->fields_value, $this->getConfigFieldsValues()); return $output . $helper->generateForm($fieldsForm); } protected function getConfigFieldsValues() { return array( self::CONF_SIWA_ORDEREXPORT_STATES.'[]' => Tools::getValue( self::CONF_SIWA_ORDEREXPORT_STATES, explode( ',', Configuration::get(self::CONF_SIWA_ORDEREXPORT_STATES) ) ), ); } Maybe one of you has an idea. Thanks in advance for your help! Link to comment Share on other sites More sharing options...
SIWA_Fabian Posted June 24, 2020 Author Share Posted June 24, 2020 So I narrowed it down a lot. It comes from the creation of the form which allows the user to change the settings of the module. The code responsible for the error looks like this now: $fieldsForm[0]['form'] = [ 'legend' => [ 'title' => $this->trans('Settings', array(), "Modules.Orderdownload.Admin"), ], 'input' => [ [ 'type' => 'select', 'label' => $this->trans('Orderstatus', array(), "Modules.Orderdownload.Admin"), 'name' => "Test for Error", 'required' => true, 'multiple' => false, 'options' => array( 'query' => $orderStates, // $options contains the data itself. 'id' => 'id_order_state', // The value of the 'id' key //must be the same as the key for 'value' //attribute of the <option> tag in each $options sub-array. 'name' => 'name' // The value of the 'name' key //must be the same as the key for the text //content of the <option> tag in each $options sub-array. ) ] This now leads to the following warning, one for every order state created in the shop: Notice in Zeile 801 der Datei /Applications/MAMP/htdocs/var/cache/dev/smarty/compile/db/56/74/db567485f5fc1b76e32f03a400289021d1354998_0.file.form.tpl.php [8] Undefined index: Test for Error Even the documentation of presta shows the coding of a back-office form element like i did it. Still I have to remove all warnings before I get technical approval by Presta. Has anybody a solution that differs from the official documentation of prestashop? Link to comment Share on other sites More sharing options...
bav_it Posted June 14, 2022 Share Posted June 14, 2022 (edited) Have you solved it? Later edit: Found the issue! All values from this form must be declared in a key like this fields_value. Look here for example: $form = [ 'form' => [ 'legend' => [ 'title' => 'Adaugare oferta', ], 'input' => [ [ 'name' => 'bav_title', 'type' => 'text', 'label' => $this->l('Titlu'), 'size' => 500, 'required' => true, ], [ 'name' => 'bav_image', 'type' => 'file', 'label' => $this->l('Imagine'), 'required' => true, 'value' => '' ], [ 'name' => 'bav_subtitle_row_1', 'type' => 'text', 'label' => $this->l('Subtitlu 1 (bold)'), 'value' => '', 'size' => 500, ], [ 'name' => 'bav_subtitle_row_2', 'type' => 'text', 'label' => $this->l('Subtitlu 2'), 'size' => 500, ], [ 'name' => 'bav_description', 'type' => 'textarea', 'label' => $this->l('Descriere'), 'size' => 5000, ], [ 'name' => 'bav_product_link', 'type' => 'text', 'label' => $this->l('Link produs'), 'size' => 2000, ], [ 'name' => 'bav_sort_order', 'type' => 'text', 'label' => $this->l('Ordine sortare'), 'size' => 10, ], [ 'name' => 'bav_is_visible', 'type' => 'select', 'label' => $this->l('Este vizibil'), 'options' => ['1' => 'Da', '0' => 'Nu'], ], [ 'name' => 'bav_start_on', 'type' => 'date', 'label' => $this->l('Oferta incepe pe'), ], [ 'name' => 'bav_expires_on', 'type' => 'date', 'label' => $this->l('Oferta expira pe'), ], ], 'fields_value' => [ // fixes undefined notices in smarty (is looking here to fill form with values) 'bav_title' => '', 'bav_image' => '', 'bav_subtitle_row_1' => '', 'bav_subtitle_row_2' => '', 'bav_description' => '', 'bav_product_link' => '', 'bav_sort_order' => '0', 'bav_is_visible' => '1', 'bav_start_on' => '', 'bav_expires_on' => '', ], 'submit' => [ 'title' => 'Adauga',//$this->l('Save'), 'class' => 'btn btn-default pull-right', ], ] ]; I know this answer may not help you as two years passed, but it may help others. Edited June 14, 2022 by bav_it (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now