Magento 1.9 – System Config Multiselect Default All Selected

default valuesmagento-1.9system-configurationsystem.xml

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>

Best Answer

Use DataScript to store data in config module.

How to create data script

http://inchoo.net/magento/magento-install-install-upgrade-data-and-data-upgrade-scripts/

In datascript simply call the core config module and save your data

$myDynamicValue = '1,2,3';
Mage::getConfig()->saveConfig('section/group/field', $myDynamicValue, 'default', 0);