Get Free Audit

Multistore in Magento 2.0

Oct 14, 2014

2424 Mishel Soiko

We need to create two web sites: store1.com and store2.com.

First, let’s create the first site. Unzip Mаgentо into the folder on the server. Then install it, configure and now the site is ready to use.

You can install the second store in the same way as the first one, but I would like to describe a new interesting feature: the “Pub” folder in the Magento root.

The store domain can be connected both to the folder into which Magento has been unzipped and to the Pub folder. In both cases we will get a full running store.

Developers have placed 2 sub-folders here:

pub/static is similar to the folder Skin from the first Magento

Pub/media – the media folder has also been moved here.

Admin panel

Let us create the second store: Stores / Settings / All Stores

screen-1Multistore

Be sure to remember the code of the store.

screen-2Multistore

Now we match the new domain with the second store, that we have just created: Stores / Settings / Configuration

screen-3Multistore

Connecting the second domain

  • Let’s also connect the second domain to the Pub folder

Magento is not able to detect from which domain the user has come, that is why we need to help it.

Add the following into the file pub/index.php


Everything is ready now.

  • What if we make a copy of the Pub folder and connect the domain to that copy?

For example, let’s name the folder as “pub2 “.

screen-4_1Multistore

Add the following into the file pub2/index.php

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey


When we assign another folder for the store, we should remember that the files, that define the appearance of the store, will also be placed here.

(Filesystem::STATIC_VIEW_DIR).

Yet with the Media files the situation is a bit different. By default they are loaded only into the Pub folder, even if the product is available in several stores. When visiting the second store we will not be able to see any product images yet.

This means that by creating a separate folder for the second store we have only made things more difficult. But let’s fix this.

We need the following two files:

pub2/opt/magento/var/resource_config.json

pub2/get.php

In the JSON configurations we fix the Media folder: “media_directory”:”\/media”

And also make several improvements for get.php, which is responsible for loading images.


All stores are working now.

More changes

But what if we separate the Pub folder from Magento? The Media folder collects all uploaded images, that is why we leave it on its place. So we will separate only the appearance of our stores.

This is how we do this: (In this example splitting into two Pub folders  seemed more logical to me,  but this is not a must)

screen-5Multistore

What does this give to us?

For instance, this way we can create separate zones for developers and frontend developers.

In this case we will need to make the following changes:

pub/index.php,    pub/static.php,      pub/cron.php


pub/get.php (in this file, in addition to the described above, I also had to fix the displaying of temporary uploaded images)

Conclusion

Of course, we will be able to see if these ideas can be applied only after Magento 2 is released.

But in this article I just wanted to experiment and share my thoughts.

Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

3 Comments

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *