4

I am using Magento to host three different stores, on LAMP stack.

I have created 3 different websites and store views in Magento backend ( All having different DN ). There is a functionality to switch among stores, ie if user is on store 1 and clicks on store 2 he/she/it should redirected to respective page on store 2.

Currently, whenever user clicks on different store link, it is taking back to same store.

I tried setting up different host entries for each domain name, associating a variable in server vhost and loading store based on url requested ( through php $_Server[referer] but with none I have been successful. Please guide me if you have faced similar problem in past and know if I am missing something. Any constructive comment is welcomed.

3

Well, I believe the easiest way to do what you're asking is to put the store view in the URL. Although there is another method that I know of.

1) http://docs.magento.com/m2/ce/user_guide/stores/store-urls.html You could follow this method to include the store view in the URL itself, and then when you link you can post the different stores in various links. When you link you could do

http://www.yourdomain.com/magento/store-view-2/index.php/url-identifier

2) You could have a "store switcher" link. I am unsure based on your question why you are switching stores. Do they have different languages or products? either the case the result is the same. Let's assume you have different products because you want a store to represent a different brand but you have the same products and categories. You could have links on main store or store view 1 that links to store-view-2 and store-view-3.

<a href="?___store=store-view-2&___from_store=store-view-1" style="color: #222222;">Store 2</a>
<a href="?___store=store-view-3&___from_store=store-view-1" style="color: #222222;">Store 3</a>

Now if you put that into say your header or footer, it will keep any page you're on and if you have created the same pages in the other store views it simply switches stores and keeps the page. This also works great for languages. Say you speak English and Spanish, you can keep the same page, in the CMS it has the same identifier - one is enabled for each store view, and naturally the english store view has english text and photos and the spanish one has spanish text and photos. Based on this it will show the user which one they want simply based on stores.

Long response but I had to make some assumptions about what you're doing. There are also far better ways to do what I am mentioning to you in the actual code and have it more efficient such as creating a variable and calling it then that calls the store view based on your URL and a couple of other optimizations.

Both of these methods will get you going in the right direction.

For any reviewers / Googlers - please post in comments which one works best for you for future readers.

2
  • Thanks @camdixon, I solved the problem by separating vhost config for each site differently and putting store web view as an env variable. In Index.php, the view is being called based on variable passed. It did not work in same file. Jul 21 '16 at 19:32
  • 1
    I see - your issue was more config related. I thought you had the URLs separated already and setup as seperate working stores in the backend.
    – camdixon
    Jul 22 '16 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.