System Config Multiselect default all selected

by Jay Ghosh   Last Updated March 16, 2017 06:09 AM

I have a system config field of type multiselect which will be populated using the catalog/product_attribute_collection. This is a part of the system.xml that defines it.

  <attributes>
       <label>Choose Attributes to JSONize</label>
       <frontend_type>multiselect</frontend_type>
       <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>

<source_model>package_module/system_config_attributes</source_model>
  </attributes>

Now I want all of the values in the multiselect to be selected by default. Since the default values for system config are defined in the config.xml, I'm not sure how to choose all as default.

This is the section of config.xml which is relevant to the question

<default>
    <mytab>
        <mysection>
            <attributes><!-- ***WHAT SHOULD I WRITE HERE*** --></attributes>
        </mysection>
    </mytab>
</default>


Answers 1


I give multiselect example.

<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 multiselect option in your module in this path

your_namespace/yourmodel/Model/System/Config/Source/View.php

Add below code in 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'),
        );
    }
}
calypso
calypso
March 16, 2017 05:23 AM

Related Questions


Implement "Use system value" in custom module

Updated March 29, 2018 15:09 PM


System Config page at backend is showing Blank page

Updated March 24, 2017 07:09 AM


Magento 2: Store Config Missing on Backend

Updated May 14, 2018 21:09 PM