Source: Magento 2 dev docs (official) – Multiple websites or stores.
Consider the following terms:
-
Website—is the top-level container for sites, shipping methods, payment methods, and more. To create completely separate sites that do not share cart, shipping methods, or other you must create separate websites.
Website customer accounts can be shared between multiple websites within a single Magento instance. A website contains at least one store. Catalog prices should be managed at the website level.
-
Store—is contained by a website. In turn, a store contains at least one store view.
Multiple stores can share cart, user sessions, payment gateways, and more, but they have separate catalog structures and Catalog price.
Catalog Qty (inventory) can not be managed at the store level. Inventory is managed at Website or Global level only.
Store views change the way pages are presented, and are typically used to display a store with different layouts or languages. You can manage different currencies per store view.
Cas pratique
Ressources officielles utilisées:
- Set up multiple websites, stores, and store views in the Admin
- Tutorial—Set up multiple websites or stores with nginx
Structure du projet en Websites > Store (group) > Store view:
Structure du projet vu de l’admin (Stores > All stores [Settings]):
N’hésitez pas à agrandir l’image.
Attention: voir la documentation officielle pour savoir comment affecter les différentes URLs à chaque store view.
Fichier <racine_projet>/docker/.env
en fonction de cette structure de sites:
ATTENTION: votre fichier .env
ne se trouvera pas nécessairement dans un dossier docker/
. Il se trouve au même niveau que le fichier docker-compose.yml
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
COMPOSE_PROJECT_NAME=vitalconcept # HOSTS MAGENTO_VIRTUAL_HOST=vitalconcept.local,vital-agriculture.local,vital-equideos.local,vital-paysage.local,vital-agriculture-be.local [...] # MULTI SITE MAGENTO_RUN_BASE_TYPE=website MAGENTO_RUN_BASE_CODE=base MAGENTO_RUN_BASE_URL=vitalconcept.local MAGENTO_RUN_FR1_TYPE=store MAGENTO_RUN_FR1_CODE=agriculture_FR_fr MAGENTO_RUN_FR1_URL=vital-agriculture.local MAGENTO_RUN_FR2_TYPE=store MAGENTO_RUN_FR2_CODE=equideos_FR_fr MAGENTO_RUN_FR2_URL=vital-equideos.local MAGENTO_RUN_FR3_TYPE=store MAGENTO_RUN_FR3_CODE=paysage_FR_fr MAGENTO_RUN_FR3_URL=vital-paysage.local MAGENTO_RUN_BE1_TYPE=store MAGENTO_RUN_BE1_CODE=agriculture_BE_fr MAGENTO_RUN_BE1_URL=vital-agriculture-be.local MAGENTO_RUN_BE2_TYPE=store MAGENTO_RUN_BE2_CODE=agriculture_BE_nl MAGENTO_RUN_BE2_URL=vital-agriculture-be.local/nl MAGENTO_RUN_TEST_TYPE=store MAGENTO_RUN_TEST_CODE=test_store_view MAGENTO_RUN_TEST_URL=test.vitalconcept.local |
Notes:
- Pour l’ensemble des variables d’environnement
MAGENTO_RUN_FR1_*
,FR1
est un libellé libre qui vous permettra d’identifier votre website ou votre store view (j’y viens…). - Pour la variable d’environnement
MAGENTO_RUN_*_TYPE
, vous avez le choix entrewebsite
etstore
(cf. colonne 1 (website) et 3 (store view) dans l’admin: Stores > All stores [Settings]). - Pour la variable d’environnement
MAGENTO_RUN_*_CODE
, renseignez le code de votre website ou de votre store view (en fonction du choix fait précedemment). - Pour la variable d’environnement
MAGENTO_RUN_*_URL
, renseignez l’URL précisée dans les champs Base URL, Base Link URL, Secure Base URL, Secure Base Link URL, accessibles dans l’admin depuis Stores > Configuration [Settings] > Web [General] > puis sous « Store View » (juste sous le titre « Configuration », en haut à gauche) choisissez un scope.
Fichier <racine_projet>/app/etc/env.php
en fonction de cette structure de sites:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<?php return [ 'system' => [ 'stores' => [ 'default' => [ 'web' => [ 'unsecure' => [ 'base_url' => 'http://vital-equideos.local/' ] ] ], 'fr_agriculture' => [ 'web' => [ 'unsecure' => [ 'base_url' => 'http://vital-agriculture.local/' ] ] ], 'fr_paysage' => [ 'web' => [ 'unsecure' => [ 'base_url' => 'http://vital-paysage.local/' ] ] ], 'fr' => [ 'web' => [ 'unsecure' => [ 'base_url' => 'http://vital-agriculture-be.local/' ] ] ], 'ne' => [ 'web' => [ 'unsecure' => [ 'base_url' => 'http://vital-agriculture-be.local/' ] ] ] ] ] ]; |
Attention: les fichiers de configuration type config.php
et env.php
ne seront pris en compte qu’après avoir exécuté la commande bash $ magento app:config:import
.
Fichier hosts
(de Windows pour ma part)
1 2 3 4 5 6 |
192.168.56.101 vitalconcept.local mail.vitalconcept.local adminer.vitalconcept.local 192.168.56.101 vital-agriculture.local 192.168.56.101 vital-equideos.local 192.168.56.101 vital-paysage.local 192.168.56.101 vital-agriculture-be.local 192.168.56.101 test.vitalconcept.local |
Extrait fichier docker-compose.yml
(image « web » uniquement):
Les lignes env_file: .env
et VIRTUAL_HOST: "vitalconcept.${EXT:-local},vital-agriculture.${EXT:-local},vital-equideos.${EXT:-local},vital-paysage.${EXT:-local},vital-agriculture-be.${EXT:-local},test.vitalconcept.local"
ont été ajoutées/modifiées par rapport à notre configuration originale.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
version: '2.1' services: web: image: docker.netapsys.fr/magento2-nginx-php71:v0.1-dev expose: - '80' env_file: .env environment: VIRTUAL_HOST: "vitalconcept.${EXT:-local},vital-agriculture.${EXT:-local},vital-equideos.${EXT:-local},vital-paysage.${EXT:-local},vital-agriculture-be.${EXT:-local},test.vitalconcept.local" VOLUME_UID: '${UID:-1000}' VOLUME_GID: '${GID:-1000}' DEVELOPER_MODE: 1 MAGENTO_MODE: developer MAGENTO_SERVERNAME: "*.vitalconcept.${EXT:-local}" MAGENTO_DOCUMENTROOT: $HOME/magento2/vitalconcept EMAIL_FORWARD_HOST: 'mailcatcher:1025' working_dir: $HOME/magento2/vitalconcept volumes: - '$HOME/.composer:/var/www/.composer' - './data/crontab:/data/crontab' - '$HOME/magento2/vitalconcept:$HOME/magento2/vitalconcept' networks: - default - proxy |
Attention: il faut re-up le container Docker après chaque ajout de site/nouvelle URL:
1 2 |
$ docker-compose down <container> // down == stop && rm |
magento.conf
de nginx:
Se connecter en bash au docker « web » et vérifier que les URLs ont bien été écrites dans la configuration nginx en tapant la commande suivante:$ cat /etc/nginx/sites-enabled/magento.conf
Assigner une root catégorie du catalogue à un store (à un sous-domaine/une URL)
Magento 2 User Guide: Root Categories > Step 3: Assign the Root Category to the Store.