prestashop_newuser Posted January 1, 2015 Share Posted January 1, 2015 I am doing a small module in Prestashop. In that module I have used multiselect with helperform. So my code is like this array('type' => 'select','cols' => 8,'class' => 'chosen-product-selct selected_products ','multiple' => true,'label' => $this->l('Selected Products'),'name' => 'selected_products[]','options' => array('query' => $product_query,'id' => 'id','name' => 'product_name'),'desc' => $this->l('Select products from products list.'),), Here I am saving those multiselected values to the database. But when I am doing edit no saved values has been selected in the box. The box is totally empty. for getting the result I am doing this public function getConfigFieldsValues() {'selected_products[]' => Tools::getValue('selected_products', Configuration::get('selected_products')),} Its not showing the values that has been entered.So can someone tell me how to solve this issue? Any help and suggestions will be really appreciable. Thanks Link to comment Share on other sites More sharing options...
Dev Franco Posted March 31, 2015 Share Posted March 31, 2015 (edited) Same issue here, Did you solve it?? Edited March 31, 2015 by Dev Franco (see edit history) Link to comment Share on other sites More sharing options...
erouvier29 Posted March 31, 2015 Share Posted March 31, 2015 (edited) Hi, here is some info that may help. Assuming the multiselect input defined as above, $product_query shall be set before the definition with the array of the products that will be proposed to selection (incl. at least fields 'id' and 'product_name'). This is how the box will be populated. Then, before generating the form, the helper variables shall be set as e.g. $this->helper->tpl_vars['fields_value']['selected_products[]'] = explode(';', Configuration::get('SELECTED_PRODUCTS')); This is how the products will be pre-selected (according to the current config) when opening the form. As values in Configuration are made of text, the stored string is transformed to the array of pres-selected ids. And finally, somewhere in postProcess, the new selection can be stored as configuration as e.g. Configuration::updateValue('SELECTED_PRODUCTS', implode(';', Tools::getValue('selected_products'))); Just the opposite, the array of selected ids is transformed into a string that can be stored in Configuration. Note that the final '[]' is used for the name of input and the helper setter, but not for the Tools getter. A little bit confusing, isn't it? Regards Edited March 31, 2015 by erouvier29 (see edit history) 1 Link to comment Share on other sites More sharing options...
prestashop_newuser Posted April 2, 2015 Author Share Posted April 2, 2015 Hi, here is some info that may help. Assuming the multiselect input defined as above, $product_query shall be set before the definition with the array of the products that will be proposed to selection (incl. at least fields 'id' and 'product_name'). This is how the box will be populated. Then, before generating the form, the helper variables shall be set as e.g. $this->helper->tpl_vars['fields_value']['selected_products[]'] = explode(';', Configuration::get('SELECTED_PRODUCTS')); This is how the products will be pre-selected (according to the current config) when opening the form. As values in Configuration are made of text, the stored string is transformed to the array of pres-selected ids. And finally, somewhere in postProcess, the new selection can be stored as configuration as e.g. Configuration::updateValue('SELECTED_PRODUCTS', implode(';', Tools::getValue('selected_products'))); Just the opposite, the array of selected ids is transformed into a string that can be stored in Configuration. Note that the final '[]' is used for the name of input and the helper setter, but not for the Tools getter. A little bit confusing, isn't it? Regards Hi, This is not working. Whenever I am closing the form and again reopening the values which has been stored in the input fields are getting lost. Can you share some code for the solution? Link to comment Share on other sites More sharing options...
erouvier29 Posted April 2, 2015 Share Posted April 2, 2015 Here it is. Works fine on PS 1.6.0.14 Regards test.php 1 Link to comment Share on other sites More sharing options...
prestashop_newuser Posted April 4, 2015 Author Share Posted April 4, 2015 Here it is. Works fine on PS 1.6.0.14 Regards test.php Hi erouvier29, Thanks for sharing the code. Its working fine. Really liked it. Thank you so much. Link to comment Share on other sites More sharing options...
aviel Posted September 22, 2015 Share Posted September 22, 2015 Does anybody has the same for 1.6.1? When the form is loaded information from object is not loaded. Link to comment Share on other sites More sharing options...
erouvier29 Posted September 23, 2015 Share Posted September 23, 2015 Hi It seems to work on 1.6.1.1 (no reason why it sould not) Did you adapt the query at the end of the source file? In the example, it loads only the names of the products with id < 10 in language with id 1 Maybe you don't have any... Regards Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 20, 2017 Share Posted September 20, 2017 i cannot download the code test.php Link to comment Share on other sites More sharing options...
Recommended Posts