12

How can I assign a default value to a config value, which i am defining in a system.xml file? Currently it defaults to 'no', but i want it to default to 'yes'.

Here is my current definition code:

<catalog>
            <groups>
                <my_val>
                    <label>My Label</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>160</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <my_inner_val translate='label comment'>
                            <label>Enable seperate cart items</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </my_inner_val>
                    </fields>
                </my_val>
            </groups>
        </catalog>
33

You can easily add default values for all configuration settings in your config.xml:

<config>
    <default>
        <cms>
            <wysiwyg>
                <enabled>0</enabled>
            </wysiwyg>
        </cms>
    </default>
</config>

At the moment I'm unable to map your system.xml setting name to the node in the config.xml

I would say it is: catalog/my_val/my_inner_val, means:

<config>
    <default>
        <catalog>
            <my_val>
                <my_inner_val>1</my_inner_val>
            </my_val>
        </catalog>
    </default>
</config>

Small tip in the end: Be careful with the int settings. Sometimes magento uses 1 and 2 for yes/no, on/off, etc.

| improve this answer | |
  • Great this is what i was trying to figure out – Gershon Herczeg Mar 1 '13 at 18:30
3

You can assign default values from your module's config.xml. Define there node with such xpath

config/default/catalog/my_val/my_inner_val.

Hope this will help.

| improve this answer | |
0

Default value store wise for custom fields for customer module create account section:

<stores>
    <default>
        <customer>
            <create_account>
                <postcode_validation>postcodevalidation-GB</postcode_validation>
                <postcode_format>Accepted Formats:- AA9A 9AA, A9A 9AA, A9 9AA, A99 9AA, AA9 9AA, AA99 9AA</postcode_format>
                <postcode_regexp>([A-Z])([A-Z])([0-9])([A-Z]) ([0-9])([A-Z])([A-Z]),([A-Z])([0-9])([A-Z]) ([0-9])([A-Z])([A-Z]),([A-Z])([0-9]) ([0-9])([A-Z])([A-Z]),([A-Z])([0-9])([0-9]) ([0-9])([A-Z])([A-Z]),([A-Z])([A-Z])([0-9]) ([0-9])([A-Z])([A-Z]),([A-Z])([A-Z])([0-9])([0-9]) ([0-9])([A-Z])([A-Z])</postcode_regexp>
                <postcode_uppercase>1</postcode_uppercase>
            </create_account>
        </customer>
    </default>
</stores>

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.