Quick Review for Multi-Store
Functionality
What’s
Magento Multi Store?
Magento ships with a number of very powerful features
under the hood that go mostly unnoticed by the folks that install and use it on
a daily basis. The feature we’re looking at today, the multi store functionality
happens to be one of those; and arguably, it’s one of the most advanced ones.
There isn’t a general vernacular for this feature so I’ll be just calling it
multi store from now on.
Using this multi store functionality, we can use a
single Magento installation and use it to power any number [within technical
limits, of course] of stores or websites. This is definitely a godsend for
stores that would like to sell products on different domains but would like to
have a unified administrative centre. If you need even more granular control,
you can set up different, separate stores under the same domain to
differentiate between items even better.
Step 1: Initial Preparations
First up, if you’re on your local server, you probably
entered nothing for the URL during the installation and thus Magento has the
default value stored. We’ll need to change to point it to a concrete location.
We’ll do it quickly right now.
Go to System -> Configuration and
under the Web category, change the base URL value to reflect
your local set up. I have mine working under a predictably named Magento
directory thus my URL. Please remember to add the trailing slash.
With that out of the way, we can get to the
next step: creating a root category for the new store. You may ask why. My
reasoning is that with the additional stores, the number of prospective
categories will increase as well. With organizational structure in mind, it
makes sense to keep each store’s categories in a separate root category. We’ll
be creating one now.
Just give a name to the new category and make sure it’s
set to active.
Finally, set the is anchor value to yes as well. This
is important.
Step 2: Setting up the New Site
First, we’ll set up the new site in Magneto’s back end.
In the resulting screen, key in a name for the site as
well as a code for it. Neither is really important, other than that both need
to be unique.
Step 3: Setting up the New Store
Now we’ll move on creating a new store.
This should be self-explanatory. We set the website and
category to the ones we created a few steps back. The name of the store is just
for human readability, so feel free to name it as you like. I know having the
same name for the store and category is a little confusing here. Feel free to
name it as you like in your installations. There’s no concrete naming scheme
here for you to follow.
Step 4: Setting up the New Store
View
Again, these steps should be fairly self-explanatory.
We select the appropriate website and store for the view along with keying in a
name and code for it. Additionally, remember to set its state to enable. It may
seem obvious, but we tend to forget it, so I thought a quick “heads up” was in
order.
With these, most of the back end work in Magento comes
to an end. We’ll need to revisit this later so for now we’ll focus on
Step 5: Prepping the New Domain
This is the easiest step there is. Just FTP into the server
with the working Magento installation and copy the index.php file as well as
the htaccess file over to the new domain.
Open up index.php and look for the following code at
around line 45,
$mageFilename =
'$mageFilename = 'app/Mage.php';';
Change it to the following.
$mageFilename =
'../magento/app/Mage.php';
Remember to point it to the Mage.php file of the
working installation. Both my sites run under sub folders in my server so I
just ask it to go a directory up, go into the magento folder, into the app
folder and then access the required file. Depending on your server set up, this
may vary, for example, your main installation may be in your account root while
the other site may be under a parked domain. In that case, the following code
will do.
$mageFilename =
'../app/Mage.php';
As I said, just make
sure you point Magento to the right location
Step 6: Making it all Work – the
HTACCESS file
Now open up the copied
htaccess file and append the following to it.
SetEnvIf Host .*base.*
MAGE_RUN_CODE="base";
SetEnvIf Host .* mobile_site_2.*
MAGE_RUN_TYPE="mobile_site_2";
Simple as that! Note
that we’ve used the website code we keyed in earlier. If you don’t remember it,
just go back in and copy it over. This is very important so make sure typos are
avoided.
Step 7: Final Steps
We’re pretty much done now. Just the final few steps
before we get everything working.
Go to System->Configuration and choose the web tab.
As shown in the picture above, please change the
redirect to base URL to “no.”
If you’ve noticed that the select element on the left
has extra options now, you get a cookie! Now that we have different stores, we
can now change their settings and store policies on a per store basis.
Access our second store’s view and choose the web tab.
Uncheck the use website checkbox and change the base
URL to the URL of your second domain. For this article, I did everything on my
local server so I have a sub-folder imaginatively named magento-2 as a
container for my second store front.
Click on save. And that’s about it. Go to your second
domain and start browsing through your catalog!