Jump to content
prestashop_newuser

multiple select from the module and get them in the input

Recommended Posts

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

Share this post


Link to post
Share on other sites

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 by erouvier29 (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Does anybody has the same for 1.6.1?

 

When the form is loaded information from object is not loaded.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More