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
- Store 1: Storeview
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
- Base URL: http://m1.local/
- Base Link URL: {{unsecure_base_url}}
- Storeview
m2
- Base URL: http://m2.local/
- Base Link URL: {{unsecure_base_url}}
- Storeview
m3
- Base URL: http://m3.local/
- Base Link URL: {{unsecure_base_url}}
I modify /index.php
and /pub/static/index.php
in the following way:
$params = $_SERVER;
$domain2store = array(
'm1.local'=>'m1',
'm2.local'=>'m2',
'm3.local'=>'m3',
);
if(isset($domain2store[$_SERVER['HTTP_HOST']]))
$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?