New Free Preview

Configure scope with XML in Magento

Video Lesson: Configure scope with XML in Magento

Learn how to configure scope in Magento XML by using default, websites, and stores nodes for layered store settings.

Lesson Content

XML scope structure

In Magento's XML files, scope is implemented through specific node structures that map directly to the scope hierarchy:

<?xml version="1.0"?>
<config xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <!-- Global default settings -->
    <default>
        <!-- Configuration goes here -->
    </default>

    <!-- Website-specific settings -->
    <websites>
        <website_code>
            <!-- Configuration goes here -->
        </website_code>
    </websites>

    <!-- Store view-specific settings -->
    <stores>
        <store_code>
            <!-- Configuration goes here -->
        </store_code>
    </stores>
</config>

The node names directly correspond to Magento's scope levels, making the structure intuitive once you understand the basics.

XML scope example

Let's look at how this works with a simple store information configuration:

<?xml version="1.0"?>
<config xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
		<!-- Global default -->
		<default>
		    <general>
		        <store_information>
		            <name>My Store</name>
		            <phone>1-800-555-0123</phone>
		        </store_information>
		    </general>
		</default>
		
		<!-- European Website -->
		<websites>
		    <europe_website>
		        <general>
		            <store_information>
		                <phone>+44 20 7946 0958</phone>
		            </store_information>
		        </general>
		    </europe_website>
		</websites>
		
		<!-- Spanish Store View -->
		<stores>
		    <spanish_store>
		        <general>
		            <store_information>
		                <name>Mi Tienda</name>
		            </store_information>
		        </general>
		    </spanish_store>
		</stores>
</config>

In this example:

  • The store name defaults to "My Store" globally

  • The European website overrides the phone number to a UK number

  • The Spanish store view translates the store name to "Mi Tienda"

  • The Spanish store inherits the European phone number since it's part of that website

XML merging and precedence

One of Magento's most powerful features is how it handles multiple XML files defining the same configuration paths:

  1. Non-conflicting nodes are merged together

  2. When nodes conflict, the last loaded file wins

  3. Module load order (determined by sequence tags in module.xml) affects which definitions take precedence

This creates a layered approach where modules can build upon or override each other's configurations without direct code changes.

When you're debugging configuration issues, you'll often need to check which module is providing specific XML nodes and in which scope they're being defined.