Outline all the available Magento scopes, what are the scopes available in a standard Magento install?
Magento 2 has a 4-level hierarchy: Global, Website, Store (Store Group) & Store View.
What is the difference between Magento 2 website, store, and store view?
This is the highest level in the Magento pyramid. Here you can set the only 3 options that will be the same for all stores:
- Stock - configure the main product settings.
- Price - define the same price for the products in all stores.
- Buyers - Merge all store customer data into one big database for all websites.
Global values are values that are out-of-the-box if the user has not specified. These values are usually defined within a modules
etc/config.xml
.By default, a vanilla Magento install features:
- System configurations (dependent on their scope in declarative schema
showInDefault
,showInWebsite
,showInStore
) available in Admin > Stores > Configuration. - No Products
- No Customers
- 1 Root Category + 1 Default Category without any products
- 1 Tax Rule: "Taxable goods", 3 Tax Zones / Rates: US-CA. A Non-taxable goods class is also available.
- 1 Website, 1 Store (Store group), 1 Store View.
With one Magento base, you can design various websites, for example, hats.com and pants.com. The following can be configured per Website:
- Separate Payment methods.
- Separate Shipping methods.
- A totally separate Product base - products are required to be assigned to websites individually. They can have different prices / currencies / attribute values etc.
- Separate tax classes.
- Separate (base) currencies.
- Separate Customer base - It's up to you whether your customers can log in to all shops with the same credentials.
- System configurations (dependent on their scope in declarative schema
showInDefault
,showInWebsite
,showInStore
) available in Admin > Stores > Configuration. Mostly all configurations are configurable at this level.
For each website, you can create multiple stores, but all the information will be gathered in one admin panel.
It's possible to create several stores on one Magento 2 website. The following can be configured per Store:
- Different Root Categories which allows for different products to be assigned.
The following CANNOT be configured per Store:
- All the stores within one website share the same customer accounts.
- All stores share Shipping Methods.
- All stores share Tax Rates / Zones.
- All stores share Product stock.
- All stores share Product prices.
- All currencies are identical for all the stores.
- System configurations available in Admin > Stores > Configuration.
- EAV attributes across entities Customer (including Customer Address), Products, Categories cannot be configured on a Store Group level.
And finally, for every store, you can create several store views. The following can be configured per Store View:
- Different languages.
- Different currencies.
- Different design themes
- Certain Product EAV attributes can be different such as name, or tax class (dependent on their
is_global
/scope
/is_user_defined
properties). - Different Category EAV attributes (such as name, or URL key).
- System configurations (dependent on their scope in declarative schema
showInDefault
,showInWebsite
,showInStore
) available in Admin > Stores > Configuration.
The following CANNOT be configured per Store View:
- All store views within one website share the same customer accounts.
- All store views share Shipping Methods.
- All store views share Tax Rates / Zones.
- All store views share Product stock.
- All store views share Product prices.
- All store views share the same Root Category.
- All currencies are identical for all the store views.
Here is more information on the subject with infographics!
Here is some information regarding Scope System Configuration
How do you create a new Website, Store & Store View?
Admin > Stores > Settings > All Stores
How do you set up a new Website?
For the purpose of this question we shall assume you are running an Nginx Webserver with PHP-FPM and will specifically focus on the multi-website aspect of the configuration.
server {
listen 80;
server_name mydomain.com;
set $MAGE_ROOT <MY_MAGENTO_WEBROOT>;
index index.php;
root $MAGE_ROOT/pub;
set $MAGE_CODE default;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
include /etc/nginx/defaults/magento2.conf;
}
server {
listen 80;
server_name myotherdomain.com;
set $MAGE_ROOT <MY_MAGENTO_WEBROOT>;
index index.php;
root $MAGE_ROOT/pub;
set $MAGE_CODE other;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
include /etc/nginx/defaults/magento2.conf;
}
How do you set up a new subfolder Website?
For the purpose of this question we shall assume you are running an Nginx Webserver with PHP-FPM and will specifically focus on the multi-website aspect of the configuration.
server {
listen 80;
server_name mydomain.com;
set $MAGE_ROOT <MY_MAGENTO_WEBROOT>;
index index.php;
root $MAGE_ROOT/pub;
location /cn/ {
set $code my_project_cn_store;
rewrite / /cn/index.php;
try_files $uri $uri/ /cn/index.php$is_args$args;
}
location /us/ {
set $code my_project_us_store;
rewrite / /us/index.php;
try_files $uri $uri/ /us/index.php$is_args$args;
}
location / {
set $code default;
try_files $uri $uri/ /index.php$is_args$args;
}
include /etc/nginx/defaults/magento2.conf;
}
/pub/us/index.php
<?php
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;
try {
require __DIR__ . '/../../app/bootstrap.php';
} catch (\Exception $e) {
echo
<<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">Autoload error</h3>
</div>
<p>{$e->getMessage()}</p>
</div>
HTML;
exit(1);
}
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'my_project_us_website';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
];
$bootstrap = Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(Magento\Framework\App\Http::class);
$bootstrap->run($app);
'
my_project_us_website
'; must match the Website code in Admin > Stores > All Stores
'
my_project_us_store
'; must match the Store code in Admin > Stores > All Stores