Magento for Designers: Multi-Store Functionality

Magento for Designers: Multi-Store Functionality

Tutorial Details
  • Technology: Magento
  • Difficulty: Moderate
  • Estimated Completion Time: An hour
This entry is part 7 of 8 in the Magento for Designers Session
« PreviousNext »

Magento is a stunningly powerful e-commerce platform. In this miniseries, we’ll learn how to get started with the platform, get to know the terminologies, set up a store and all related aspects of it and finally learn how to customize it to make it our very own.

In this seventh part, we’ll be learning how to set up the fabled Magento multi store functionality in simple, easy to follow steps. Excited? Let’s get started!


The Full Series


A Quick Recap

In the last few parts, we took a high level look at how Magento themes are put together, the components that drive it and how everything works together to create a working theme. We also looked at a number of API methods that Magento exposes so that we can painlessly acquire information about the product.


What Are We Learning Today?

Today, we’ll be taking a focused, step by step look at what Magento multi store is, how it can help you, and finally how to set it all up. I know it sounds interesting and you’re itching to get started, so let’s go!


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.


The Terminologies Involved

Magento’s documentation regarding this topic has a pretty decent explanation of the terminologies so I’ll make a concise introduction here:

Website: Container for stores and their related views

Store: Exactly what you’d expect but in the abstract sense. You can control your catalog through your store but nothing will be rendered on screen

Store View: These enable the actual rendering of your store. If you want to have a multi-lingual store, you’d be modifying the store view, not the store itself.

All these terminologies will start making more sense once you see them in action. For now, we’ll move on.


Today’s Goal

We’re just going to implement the system I talked about as an example above. We’re going to add a store front to a domain without installing Magento on it. Instead it’ll be using an already installed version of Magento to do all the heavy lifting. And that’s about it! I’m choosing to focus specifically on this scenario since I’ve been getting numerous messages through various channels asking how to set it up. So let’s get started!


Requirements

There are only 2 requirements/restrictions here.

  • Computing Power

    Choose your servers carefully. Running a single store on an installation often chokes most shared hosts and brings it down to its knees. Imagine running multiple store on one. If you decide to run everything off a single installation, please make sure your server will be able to handle it. If the total number of products is small, say less than 100, it shouldn’t be a concern but once you get past 500 or so, it will really begin to show.

  • Version of Magento You’re Running

    This method will require the 1.4.x.x branch or higher. Sure, you can get the functionality to work with previous versions but it is a convoluted, error prone, lengthy affair where you had to modify the core thus introducing even more work when you’ll need to upgrade in the future. Each new version is faster and brings more features to the table which means I’ll be focussing exclusively on the newer branch. If you’re still running an old branch, back everything up and upgrade. Please.


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; otherwise, Magento will spaz out.

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 Magento’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 enabled. 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 preparing the new domain.


Step 5: Prepping the New Domain

Ok, to be honest, 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 .*magento_site_2.* MAGE_RUN_TYPE="magento_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!


What We’ll be Doing in the Next Part

All that’s left now is creating a custom module; then, and I think by then this series will have runs its course. I’m thinking of finishing off with a Magento tweaks and optimization how-to, if enough people show interest for such an article.

If you do feel that something else needs to be covered before this series comes to a close, don’t hesitate to leave a comment below to let me know!


The Last Word

And we are done! Today, we learnt what Magento’s multi store functionality is and how to set it up as quickly as possible. Hopefully this has been useful to you and you found it interesting. Since this is a rather new topic for a lot of readers I’ll be closely watching the comments section so chime in there if you’re having any doubts.

Questions? Nice things to say? Criticisms? Hit the comments section and leave me a comment. Happy coding!

Siddharth is Siddharth on Codecanyon
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.sz-media.org Sz-Media

    have to setup a multistore next week, you are awesome nettuts!

  • http://www.magentothemedtemplates.com/ Magento Themed Templates

    Thanks Siddharth, great explanation, you made it so straight forward. It was prepping the domain which I was unsure about. this is one article to store in my delicious for later use.

    David

  • Levis Orgil

    WOW! nice tutorial, i need this one. that net.tuts

  • http://thedevelopertuts.com Bratu Sebastian

    So … anybody fancy selling a couple of hundred products on a couple of tens of stores ? :)

    Great article, as always!

  • http://ashsmith.co Ash Smith

    Multi-store is something I need at work really bad! Unfortunately we don’t use Magento (yet!) I may have to follow your full series and see if it’s worth the switch! 5-6 Joomla/Virtuemart Stores onto Magento will be a big challenge though!

    What would everyone else recommend? I could code a custom PHP app that grabs all orders from all other sites, saving me having to switch I guess. But being on a dedicated e-commerce system must have a lot of stuff and features Joomla/VIrtuemart doesn’t at the moment…

  • http://www.joomlagraphic.com joomlagraphic.com

    If you’re used to Joomla and VirtueMart then you need to try Redshop first. Redshop is Joomla MVC and works so much better than Virtuemart plus is has a great import feature. If you moved to Magento you’d need to use a bridge since Magento is a system in and of itself.

    Use magento and magebridge if you have more than 500 products in one store. Anything under that and you should focus on redshop or Zen Cart.

  • http://www.pominperth.com Adam

    Hey Siddharth,

    thanks for putting this great series together. One thing that I have found problematic with magento is the lack of Business to Business functionality. It would be great if you could share your experience on how to maybe setup a wholesale store whereby dependant on the type of customer they would be entitled to special payment / delivery terms maybe a quick order system where they can input product codes and qty’s etc.. any modules you recommend etc..

    I love magento as a business to customer solution but find the B2B side of things sadly lacking

    Thanks again for sharing your experience

    Ad

  • http://www.magentochina.org magentochina

    can i translate this tutorials into Chinese ?

  • http://www.peer1.com Luis Gonzalez

    I work for a hosting provider (PEER1), and I recommend not having a control panel such as Plesk installed when you use Magento. We usually recommend an OS image certified for Magento with no control panel. This is usually a problem people don’t worry about until they try to setup multi-store. By then, you’ve already spent a lot of time setting up your site.

    • http://sideradesign.com paul

      where can I get such an OS image?
      thanks

  • http://www.microdesign.nl/diensten/e-commerce/magento-webshop/ Magento webshop

    This is some tutorial, awesome work guys.
    Magento isen’t easy on designers but if you get the hang of it i think you can earn some honest money.
    the most dificult part is getting to know where all files are stored and what file outputs what html.
    the debug function under system->configuration->developer is a very handy one!

  • http://www.crearedesign.co.uk Steve Maggs

    This is an excellent series, not sure how I missed it from the start but I’ll be taking the time to go through from the tutorial one. Magento is growing fast and has been for a while but like all designers I was scared off by the MVC nature of it and the scale of the initial learning curve.

    Thanks to Magento webshop too for the debug tip, always need those :)

    • http://www.ssiddharth.com Siddharth
      Author

      Glad you like these. Thanks for reading! :)

  • http://jagatk.wordpress.com Jagat

    Excellent Post. Keep It Up :)

    • http://www.ssiddharth.com Siddharth
      Author

      Thank you for reading.

  • Andrew

    This article was a huge help. All the articles in this series are fantastic and far superior to any documentation Magento itself offers.

    • http://www.ssiddharth.com Siddharth
      Author

      Thanks, I’m glad these were useful to you! :)

      • http://www.yanni.ch Adel

        is any update for Magento 1.7

  • Gerrit

    Great, thank you.

    I had to setup my .htaccess with (I have two seperate domains in same folder):

    SetEnvIf Host .*DOMAIN_NAME.* MAGE_RUN_CODE=WEBSITE_CODE
    SetEnvIf Host .*DOMAIN_NAME.* MAGE_RUN_TYPE=website

    (no inverted comma’s, no ;)

    to get it working. Unfortunately it cannot find the shared folders e.g. images, skins, apps etc.

    Looks like I would have to add symlinks to these folders….

  • http://oggettoweb.com Stanislav Lisov

    Nice Magento Multi-store tuts, good works Siddharth!

  • http://batech.dk/ Bastian

    Hello. Thanks for the guide. But i juse cPanel and add parked domain.

    How do I set it up in htaccess and index.php?

  • http://www.indianic.com/magento-development-magento-review.html magento development

    thank you for your post. It was really helpful.
    Is it possible when importing options to remove the existing ones so to avoid duplicates? If your example is imported twice all custom options will be repeated. Can you please suggest a way to first delete the stored in the database custom options and then write the ones in the CSV import file. Perhaps this should be done just before the saving of the imported options but I don’t have idea how to code that.

  • Mike

    Hi, easy to follow tutorial!

    However, all the links and products on the second store point to the default store – that is, the second store is just a duplicate of the original.

    I must be doing something wrong but cant see what

    Any ideas?

    Thanks in advance

    • http://Truelogic.org Arun ace

      after goin through all the steps , i ended up the same way as you did … i now have 2 different domains
      ” mymagento.com ” and ” mymagento1.com ” on my localhost … but they both show the same views… as the first main site… same options same language options :( ???

      i have checked all the things regarding website , store and store view in the manage stores section… but cant seem to find the problem ?

      Please do let me know if u find a solution to this prob asap :)

      • http://www.bing.com/ Lissa

        7GhoPi With the bases loaded you struck us out with that answer!

      • Tim

        I am having the same problem after going through the changes…same categories and products are showing as the default configuration…Any solutions?

  • http://www.samba.net.br andre b fernandes

    Friends,

    is there a possibility of having multistore w/ one magento installation, but various stores with different databases, template, administrators. like wordpress mu?

    so from one single installation, we could create other stores but managed individually?

    tks very much

  • stephane

    Nice tuto indeed!

    I guess the most frequent usage of multistore capabilities of Magento, is indeed to distinguish diffrent kinf of goods to sell, so you don’t come up with a huge and complex catalog.

    What about having one catalog, one web site, and huge number of stores (suppliers/resellers) selling same stuff? ie: electornic market place kind of ecommerce solution?

    Is this something magento can be good at? Is it possible to give restricted rights to some admin users only to one store they would “own”?

    Stephane

  • Job

    I am new Magento. but I can not be edited in step 6 because they find the “SetEnvIf” Please recommend a no thanks.

  • steward

    Helpful, thank you for sharing.

    “Finally, set the is anchor value to yes as well. This is important.”

    Wish you had said why.

  • Renee Heyward

    You Said: 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.

    I do not see what your website code is. I see your store view code, but that is different than the one you put in .htaccess. I know that ‘base’ is one, where does the run type ‘magento_site_2′ come from?3

    I get a blank page btw when all of this is done. What have I done wrong?? I wanted 2 stores in one domain.

  • DAJAC

    Hello every one!

    Hope that someone can help me! I need to setup multi store functionality on 2 domain. I have domain1.com and domain2.com with a complete magentoinstallation working on domain1.com. I want to use the same installation and backend for domain2.com. I have followed the guide over and over again, I i get error everytime. My error is most of the time that it cannot find the Mage.php file.

    My magentoversion is 4.1.1.

    Do anyone have a tip to what my error can be?

    I can send the index.php and htaccess file if anyone wants to try and help me out.??

  • http://Truelogic.org Arunace

    Thanks a lot for going through all the steps to enable multi-store / multi-domain on magento… well it was explained in the documentation guide of magento but it took me a lot of time to understand the steps from that … i did know how to setup multi-domain before reading this… but after going through your tutorial… i really regret not seeing this earlier :P

    Great Job buddy … u did a lovely job of making it simple :) Good Going !!

  • http://www.dreamgoo.com Terry

    I am new Magento. So your comment is helpful to me, thanks very much!!!

  • Federico

    Hi, thanks for the great tutorial. I just bookmarked it for some works I have to do in the next few weeks. I have one question by the way: I need to have 2 different stores partially overlapping… they have to share only some categories of the main catalog. How can I achieve it?

    • http://www.beautyindulgence.co. Beauty Indulgence

      Please I have the same screnario as federico. i have followed the instructions but the stores are still not showing on home page.

      please any assistance would be appreciated

  • Michael C

    This article has incorrect information with respect to the settings in .htaccess.

    When setting .htaccess env variables (e.g.: “SetEnvIf Host .*mycoolstore.* MAGE_RUN_TYPE=…”), the MAGE_RUN_TYPE variable is an enum, so to speak, and the only valid string values are “website” and “store”, according to the official Magento documentation.
    Furthermore, there should be no reason to have to create a second directory containing the second domain’s document root. You should be able to set Apache httpd’s DocumentRoot directive to the same document root directory inside of the virtual host settings for each domain (httpd certainly doesn’t care, and neither should Magento). In other words, one directory (document root) can handle multiple stores; there’s no need to create a second document root and create multiple copes of index.php and .htaccess.

    Analogously, you don’t need to build multiple, separate houses for each person (wife, child, etc.) in your household. Instead, they all just live under the same roof. It’s the DRY principle.

    • Aaron

      I followed the instructions and it sort of worked. MagentoSite2.com displayed the shop correctly but clicking on any product would show the product but as MagentoSite1.com/product.html.

      The htaccess instructions seem to be incomplete. Can anyone help fill in the info?

      As a side note, this guide is by far the clearest I have found regarding multistore set-up thanks to the screenshots. Michael you seem knowledgeable, can you provide constructive feedback and help provide your take on setting up a Magento Multistore?

  • http://www.streetsense.com.au Jon

    So if you have 3 stores set up on the same magento installation,

    How should the .htaccess file append look?

    Is the following correct?

    SetEnvIf Host .*site.* MAGE_RUN_CODE=base
    SetEnvIf Host .*site.* MAGE_RUN_TYPE=website # ‘website’ or ‘store’

    SetEnvIf Host .*site.* MAGE_RUN_CODE=streetsense
    SetEnvIf Host .*site.* MAGE_RUN_TYPE=website # ‘website’ or ‘store’

    SetEnvIf Host .*site.* MAGE_RUN_CODE=streetexchange
    SetEnvIf Host .*site.* MAGE_RUN_TYPE=website # ‘website’ or ‘store’

    Thanks
    Jon

  • Humayun

    Hi,

    I have followed the instruction step by step but now in the middle of no where. I’m trying to setup multi store on my localhost. My magento working copy is in ‘mage1.5.1.0′ folder (location is:/www/magento1.5.1.0) and I want to setup another store called ‘German store’, so I have created a new directory: ‘/www/german_store’ and copied index.php and .htaccess from magento1.5.1.0 to german_store. I changed my index.php in ‘german_store’ so that it looks like this:
    $mageFilename = ‘../mage1.5.1.0/app/Mage.php’;

    then added following at the end of .htaccess:

    SetEnvIf Host .*mage1.5.1.0.* MAGE_RUN_CODE=”mage1.5.1.0″;
    SetEnvIf Host .*german_store.* MAGE_RUN_TYPE=”german_store”;

    Thats that, which with my understanding is done the way its been told in tutorial. But now when I try accessing http://localhost/german_store, it redirect me to http://localhost/mage1.5.1.0

    Can anyone please help what I’m missing?

  • Humayun

    Hi, I need to write a module something like Advanced Permissions, where we can assign the permissions to multiple users for multiple stores so that a particular user can see only the respective store. Where can I find the tutorial for this task?

    Thanks…

  • http://www.clearlyoptics.com fish

    Okely Dokely.

    I followed these instructions as closely as my understanding allows and I don’t seem to be in the ballpark. When I go to my second domain, All I get is a readout of the index.php file. Does anyone have any suggestions on what I’m doing wrong? It would seem I am lost somewhere in the index.php and/or the .htaccess file.

  • http://psdtomagento.net tuba

    Very good magento multistore tutorial and worked perfectly. thank you!

  • Kenny

    Hi Siddharth,

    This is a great steps by steps tutorial, probably the most precise one that I have found in the past few days researching in setting up multiple store, however, does it shares the cart?

    I have been running into a lot of trouble getting that set up, it manage to switch the stores, but not sharing the cart. Please tell us how can that be set up. Thanks!

  • Marc

    Hi Siddharth,

    very great tutorial!!

    I’m just looking something like this but I want to know if have one central store with his inventory, and also have three other stores with his owns inventory, show the inventory of the central stores in the other stores?

    Is possible?
    Thanks!!!

  • http://www.sterlingsieraden.nl Sieraden

    I just CANNOT get this to work, argh! I don’t have a clue where I am going wrong :\

  • Richie

    Does anybody know how, or even if it’s possible, to set up a magento multi site instance with a shared basket across all domains?
    My client wants to do the same thing as quidsi (see yoyo.com, soap.com, diapers.com) with 3 seperate sites, managed via one common admin, using a common catalogue with different front end template but a common basket that persists across all sites.

    However I haven’t done this before and I’m not sure where to even start! Has anybody got any experience of this or know of any documentation which outlines the approach?

    Thanks,
    Richie

    • Ken

      Hi Richie –

      Did you ever figure out how to set up a site similar to Quidsi – multiple tabs at the top, pointing to individual websites (ideally with a shared shopping cart)? If anyone has any tips, suggestion, please e-mail me at (kenbradley-at-yahoo-dot-com). Thank you.

      Ken

  • Dane

    Hey Guys,

    Any update on getting this working with a single/common cart?

    Thanks,

    – Dane

  • http://webdeveloperdepot.com Parthvi

    Hi Siddharth,

    First of all, great Tutorial.

    I am managing multiple store with single admin, which shares the single cart too.

    In magento if you want to share single cart with multiple domain you need to create different store under same websites.

    My Problem is:

    I have the site working with Magento Multistore. All the store have different root category, theme, logo & default message.

    When I add one product from store1, go to store2 & add product from store2. When i click on My Cart it will show me both the product from store1 & store2.

    The problem is that when i click on product1 from store1 from the cart viewing from store2, product detail page will open with original theme(store1 theme), but it try to make the logo, root categories & default message of store2.

    How can i change it so when it open product from anywhere it must be open from it’s original logo, root categories, default message?

    I use the folder method(index.php & .htaccess) to create multiple store.

    I also check http://www.gap.com it wors perfect. I want the same functionality.

    Really need your help! Anyone know hoe to do this?

    Thanks,
    Parthvi Shah

  • Andreas

    Thank you for your work, Siddharth.

    Please post an updute for a current Magento version,

    thank you.

  • http://www.yanni.ch Adel

    Hi Siddharth,
    I just need your help, can you do This Multistore Configurations on my webhosting and let me pay for your great work.

    please contact me at info@yanni.ch

    would be very nice and kind of you

    best regards

    adel

  • Mira

    Just found this page http://www.shopping-cart-migration.com/magento-multi-store-migration, so it seems that now Cart2Cart supports multistore migration ? Does it mean, that I should first built my store design and then migrate products, or vise versa?

    ⬇ Drag and dro

  • Susan

    Hi, Siddharth,
    Thank you for the tutorial but could you possibly update your instructions for Magento 1.7 please. The index.php is different from older version, and there may also be other differences.

    I am trying to create a second website in 1.7, and can’t follow instructions written for older version as far as url redirecting is concerned.

    Thank you.
    Susan Proctor