Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to switch store views - Magento 2 #47

Closed
christian-walker opened this issue Dec 9, 2019 · 9 comments
Closed

How to switch store views - Magento 2 #47

christian-walker opened this issue Dec 9, 2019 · 9 comments

Comments

@christian-walker
Copy link

For a project that I'm working on this is how we switch from store to store within the vagrant local env. that uses a docker container.

Within the index.php file:
$params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'extranet'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class); $bootstrap->run($app);

By doing this we're able to maintain the same url but switch themes based on the store code. This works in the vagrant env. however this doesn't seem to work in the warden env.

Any ideas why?

Thanks!

@christian-walker christian-walker changed the title How to switch store views How to switch store views - Magento 2 Dec 9, 2019
@davidalger
Copy link
Collaborator

@christian-walker Are you making those changes in index.php or pub/index.php? Warden uses pub/index.php as the application entry point on M2 environments. What I would recommend is taking a look at the information here:

The above links show how to handle multi-site setups, and the 2nd one demonstrates how to setup store codes by domain for use on local (without impacting prod, stage, etc).

@christian-walker
Copy link
Author

Thanks @davidalger I'll take a look.

@christian-walker
Copy link
Author

christian-walker commented Dec 12, 2019

@davidalger if I use willhen2.test, do I add it like this in the .env TRAEFIK_HOST_LIST=app.willhen.test,willhen2.test or is it like this:
TRAEFIK_HOST_LIST=app.willhen.test,app.willhen2.test

@christian-walker
Copy link
Author

@davidalger also for subdomains like this b2b.willhen.test, would I still have to add app at the beginning in the browser or would it just be https://b2b.willhen.test

@davidalger
Copy link
Collaborator

@christian-walker The domains can really be whatever you want them to be, no need for app to be there. That's merely the default.

When you set the label traefik.frontend.rule: Host:${TRAEFIK_HOST_LIST} in the project override file, that label replaces the default one, so whatever you specify there will be routed exactly as you specify it, no magic applied. So you would want TRAEFIK_HOST_LIST=app.willhen.test,app.willhen2.test in the .env file to use app sub-domain on the two different domains. If you're wanting to use b2b as the sub-domain, just specify that in the host list instead.

As a general rule, for my own projects here at Mediotype, I actually tend to not use the app sub-domain and do something like site1.client.test and site2.client.test. Use what works best for you.

@christian-walker
Copy link
Author

@davidalger thanks, that makes sense. So for my second store I set it up with subdomain b2b.willhen.test like this:

https://share.getcloudapp.com/jkunnLv5
https://share.getcloudapp.com/WnuEEYpb
https://share.getcloudapp.com/bLuGGAvg

But its still forwarding to the first site b2c.willhen.test

@christian-walker
Copy link
Author

@davidalger looks like I needed to run composer dump-autoload after adding the new stores.php file to it. All good now! Thanks!

@christian-walker
Copy link
Author

@davidalger I've added the stores.php file and ran composer dump-autoload after running setup:di:compile and setup:upgrade and the site is still forwarding to the main site. Do you have any other suggestions?

@davidalger
Copy link
Collaborator

@christian-walker Afraid not. Don't recall ever encountering an issue in which Magento redirects to the wrong store/website when the codes are properly set and passing to the application in $_SERVER as environment variables. Use of the stores.php file has worked quite reliably for me. I'd see what you can do to see why composer is not loading it (although if it's configured as outlined in the referenced links above, I'm at a loss on that one as well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants