I have a blank Magento 2.0 setup and want to create one website with 2 stores, one of them with 2 storeviews and the other store with just one store view. Most important: All of these 3 storeviews shall share their cart contents, login, etc.. Stores just have different categories. Just like this figure shows:

  • Website frontendbase on m1.local
    • Store 1: Storeview m1
    • Store 1: Storeview m2
    • Store 2: Storeview m3

Now, when I browse to m1.local , m1 from store 1 displays, perfectly. There is a drop down button at the top right corner, providing a link to the second storeview m2. Clicking that link creates a POST request to /stores/store/switch which then redirects me with a 302 status code to m1.local again, showing me the m2 storeview. At the very bottom of the page, I see another dropdown button providing a link to the other store. Clicking that does the same as above and takes me to storeview m3. I can sign in in any storeview, add products to the cart, and I can switch between stores and storeviews as I like, no problem.

Now I want the storeviews to run on separate domains. So, in the backend's store configuration, under General > Web, I set the following things:

  • Default config
    • Auto-redirect to Base URL: No
  • Storeview m1
  • Storeview m2
  • Storeview m3

I modify /index.php and /pub/static/index.php in the following way:

$params = $_SERVER;
$domain2store = array(
    $storecode = $domain2store[$_SERVER['HTTP_HOST']];
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = isset($storecode) ? $storecode : '';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

Cache cleared, all indexes flushed.

Now, when I browse to m1.local I can switch to the other storeviews as above. But, like randomly, I get static resources loaded from a different domain than I am on with the main request. E.g. I am on m1.local, but css + image files get loaded from m2.local. Also, the storeview drop down button does not work any longer as expected. Sometimes it takes me to the right domain, sometimes to the wrong one. Also, when I sign in with a user/password, I am no longer signed in after switching to another storeview.

I am running the same setup on a) Debian, Apache 2.2, PHP 5.6 and on b) Windows 7, Apache 2.4, PHP 5.5 . Both show exactly the same problems when I configure different domains per storeview.

I went through quite a few tutorials for setting up a multi-domain, beginning with the documentation on http://devdocs.magento.com/guides/v2.0/config-guide/bootstrap/mage-run.html Most pages just suggesst different approaches for assigning the right run code to $_SERVER['MAGE_RUN_CODE'].

I must be missing something else, or?

=== Edit ===

In the meantime I figured out that a shared cart only works if the user logs into his account. So, the basic question for me is: How do I set up Magento 2 to provide a shared cart without the need to log in?

  • Note: Ignore spaces in links - Stackexchange says I cannot post more than two links with my poor reputation :/
    – Anse
    Dec 9, 2015 at 11:23
  • I've fixed that for you ;)
    – 7ochem
    Dec 9, 2015 at 11:26
  • Thanks a lot! Prevents readers from thinking I've made a lousy mistake in the configuration. :)
    – Anse
    Dec 9, 2015 at 11:29
  • @Anse: Were you able to fixed it?
    – amitshree
    Jan 22, 2016 at 4:30
  • No, I could not solve it yet. I tried an approach described here but that did not work at all. I reported that all to my boss and it seems we're going without a shared cart for the moment.
    – Anse
    Jan 22, 2016 at 12:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.