21

With custom modules I prefer to put system config settings in config.xml (the default settings part). This makes it easier when I push code from my local machine to a dev/staging/live environment as I don't need to go into admin and re-enter settings. There are other benefits too - it can be quicker to do things in a text editor and you can always have a sensible default if there is something in the config.xml for that.

I would like to do this for a multi-website Magento store that has different shipping prices for different websites (and store views). At the moment my stores are called 'euro', 'usd' and 'gbp'. The 'euro' view takes the admin defaults with no over-ride at the website level whereas 'gbp' and 'usd' views are with the over-ride at website level.

    ...
    <default>
    <carriers>
        <my_courier>
            <stuff_goes_here_such_as_price/>
            <price>15.00</price>
            ...
        </my_courier>
    </carriers>
</default>

2 Answers 2

28

You can add this using the <stores> node in your config.xml as follows.

<stores>
    <store_code>

You can also do this on website level with the <websites> node in your config.xml as follows.

<websites>
    <website_code>

The only examples of this in the core code is in the admin side because these are the only websites or stores that are guaranteed to be in the system. Check out app/code/core/Mage/Adminhtml/etc/config.xml for an example.

<websites>
    <admin>
        <web>
            <routers>
                <frontend>
                    <disabled>true</disabled>
                </frontend>
            </routers>
            <default>
                <no_route>admin/index/noRoute</no_route>
            </default>
        </web>
    </admin>
</websites>
4
  • 1
    Did not know this! Can you expand to show this with example default values so it's clear where it goes? Nov 27, 2014 at 19:21
  • Thank-you very much! I suspect I will have to do some experimentation to get this to be actually working with my particular module, but it is great to learn something new! Thanks again! Nov 28, 2014 at 11:27
  • @David Manners - that is actually working nicely. Next question - the tick boxes of 'use default', how can I unset them on a store/website level? Nov 28, 2014 at 12:29
  • 1
    Worth noting this also works in Magento 2! Feb 15, 2017 at 9:06
0

What David explained is still valid and applicable for Magento2

Here is an example:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <!-- Default Config -->
    <default>
        <section_name>
            <group_name>
                <field_name>0</field_name>
            </group_name>
        </section_name>
    </default>
    <!-- Store Config -->
    <stores>
        <store_code>
            <section_name>
                <group_name>
                    <field_name>0</field_name>
                </group_name>
            </section_name>
        </store_code>
    </stores>
    <!-- Website Config -->
    <websites>
        <website_code>
            <section_name>
                <group_name>
                    <field_name>0</field_name>
                </group_name>
            </section_name>
        </website_code>
    </websites>
</config>

... and if looking for an example in the source code, take a look at:

vendor/magento/module-backend/etc/config.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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