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>

Henry's Cat
  • 2,045
  • 2
  • 15
  • 23

2 Answers2

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>
David Manners
  • 27,241
  • 9
  • 76
  • 220
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
diazwatson
  • 2,430
  • 2
  • 27
  • 37