Magento: System / Config Add a custom value to MultiSelect

I created one simple module. I created system.xml. there is one field Multiselect . I want to add a custom value to the multiselect field.

Can I add a custom value to the multiselect field?

<Data translate="label"> <label>Select Socail Media</label> <comment>Select Social Media To fdisplay ion Front Side</comment> <front_end_type>multiselect</front_end_type> <source_model>adminhtml/system_config_source_country</source_model> <sort_order>3</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </Data> 

in the Multiselect parameters I want to add my custom option: Data1, Data2, Data3, etc.

How can i do this? is it possible?

+4
source share
1 answer

yes, you can create in such a way as to add below code to system.xml

 <fields> <view_style translate="label"> <label>Display Settings</label> <frontend_type>multiselect</frontend_type> <source_model>yourmodule/system_config_source_view</source_model> <sort_order>40</sort_order> <show_in_default>1</show_in_default> </view_style> </fields> 

create one file for the multiselect option in your module along the way

your_namespace / yourmodel / model / System / Config / Source / view.php

Add below code to your View.php

 class YourNamespace_YourModule_Model_System_Config_Source_View { /** * Options getter * * @return array */ public function toOptionArray() { return array( array('value' => 0, 'label' => Mage::helper('adminhtml')->__('Data1')), array('value' => 1, 'label' => Mage::helper('adminhtml')->__('Data2')), array('value' => 2, 'label' => Mage::helper('adminhtml')->__('Data3')), ); } /** * Get options in "key-value" format * * @return array */ public function toArray() { return array( 0 => Mage::helper('adminhtml')->__('Data1'), 1 => Mage::helper('adminhtml')->__('Data2'), 3 => Mage::helper('adminhtml')->__('Data3'), ); } } 

Also use this link for more details.

Hope this helps you.

+11
source

Source: https://habr.com/ru/post/1500854/


All Articles