Store Hierarchy
Magento implements a three-tier hierarchy that enables complex multi-store architectures. Understanding this hierarchy is critical because configuration scope, catalog assignment, and URL routing all depend on it.
The term "Store" is used inconsistently in Magento. In the admin UI, "Store" refers to a
Store Group (middle tier), while "Store View" is the bottom tier. In code,
StoreInterface represents a Store View. The database table
store also represents Store Views, not Store Groups.
Scope Configuration System
Configuration values can be set at three scopes, with more specific scopes overriding less specific ones.
The ScopeInterface defines the constants used throughout Magento for scope resolution.
Configuration Retrieval Pattern
Core Service Interfaces
- getStore($storeId = null)
- getStores($withDefault, $codeKey)
- getWebsite($websiteId = null)
- getWebsites($withDefault, $codeKey)
- getGroup($groupId = null)
- getGroups($withDefault)
- getDefaultStoreView()
- setCurrentStore($store)
- hasSingleStore()
- isSingleStoreMode()
- reinitStores()
- getCurrentStoreId()
- get($code)
- getById($id)
- getList()
- getActiveStoreByCode($code)
- getActiveStoreById($id)
- clean()
- get($code)
- getById($id)
- getList()
- getDefault()
- clean()
- get($id)
- getList()
- clean()
- getStoreCodeFromCookie()
- setStoreCookie($store)
- deleteStoreCookie($store)
Database Schema
store_website
| Column | Type | Description |
|---|---|---|
| website_id | PK smallint | Primary key, auto-increment |
| code | varchar(32) | Unique website code (e.g., "base", "b2b") |
| name | varchar(64) | Website display name |
| sort_order | smallint | Display sort order |
| default_group_id | smallint | Default store group ID |
| is_default | smallint | Whether this is the default website |
store_group
| Column | Type | Description |
|---|---|---|
| group_id | PK smallint | Primary key, auto-increment |
| website_id | FK smallint | References store_website.website_id |
| name | varchar(255) | Store group display name |
| root_category_id | int | Root category for this store's catalog |
| default_store_id | smallint | Default store view ID |
| code | varchar(32) | Unique store group code |
store
| Column | Type | Description |
|---|---|---|
| store_id | PK smallint | Primary key, auto-increment |
| code | varchar(32) | Unique store view code (e.g., "default", "french") |
| website_id | FK smallint | References store_website.website_id |
| group_id | FK smallint | References store_group.group_id |
| name | varchar(255) | Store view display name |
| sort_order | smallint | Display sort order |
| is_active | smallint | Whether store view is active |
StoreManager Initialization
The StoreManager is the concrete implementation of StoreManagerInterface.
It relies on several repositories and the StoreResolver to determine the current store context.
The getStore() method is called thousands of times per request. The result is cached
in $currentStoreId after first resolution. Repository methods also cache their results
to avoid repeated database queries.