cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 change default store view programmatically

SOLVED
Highlighted
New Contributor

Magento 2 change default store view programmatically

i have console command that is creating store views and setting different languages for them. I want to have second console command that can change the default store view of the store. How can i do this ?

3 REPLIES
Moderator
Magento
E-Commerce

Re: Magento 2 change default store view programmatically

Magento uses the `MAGE_RUN_CODE` environment variable to determine which store to load. You could write a script which updates this environment variable automatically:

 

http://devdocs.magento.com/guides/v2.0/config-guide/multi-site/ms_over.html

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!
New Contributor

Re: Magento 2 change default store view programmatically

Hello, I'm adding the following as env variables.

MAGE_RUN_TYPE=store
MAGE_RUN_CODE=de

 I do log on the PHP $_ENV variable and the variables are there so Magento knows about them.

I have Store View with Code: de 

When i open the store home page i still go to "Default Store View" instead of the Germany store view.

Moderator
Magento
E-Commerce

Re: Magento 2 change default store view programmatically

Hard for me to say as that is in general what you need to do. As a developer, the easiest way is to look where those variables are used and see why it's not taking effect.

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!