为配置定义值设置默认值?


11

如何为我在system.xml文件中定义的配置值分配默认值?目前它默认为“否”,但我希望它默认为“是”。

这是我当前的定义代码:

<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>

Answers:


31

您可以在以下位置轻松添加所有配置设置的默认值config.xml

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

目前,我无法将您的system.xml设置名称映射到config.xml

我想说的是:catalog/my_val/my_inner_val,表示:

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

最后的小提示:小心int设置。有时,magento会使用12对于是/否,开/关等。




0

客户模块创建帐户部分的自定义字段的默认值明智的存储方式:

<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>

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.