title: Switch store programmatically magento 2
body: <p>I am trying to switch stores programmatically. I used following code to achieve it:</p>
  
  <pre><code>/**
  * @var \Magento\Store\Model\StoreManagerInterface
  */
  
  protected $_storeManager;
  
  public function __construct(
   \Magento\Store\Model\StoreManagerInterface $storeManager
  ) {
  $this-&gt;_storeManager = $storeManager;
  }
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>$this-&gt;_storeManager-&gt;setCurrentStore('YOUR_STORE_ID');
  </code></pre>
  
  <p>as given in <a href="https://magento.stackexchange.com/a/173763/59686">https://magento.stackexchange.com/a/173763/59686</a></p>
  
  <p>But no success. Only default store is displayed(selected) on storefront.</p>
  
  <p>I have also tried this url scheme <a href="http://mystoreurl.com/?___store=storeId" rel="nofollow noreferrer">http://mystoreurl.com/?___store=storeId</a> but it only display the store with given id instead of switching the store completely, Means when i visit the main url (http:mystoreurl.com), it is again displaying default store. Is there any way to switch the store programmatically just like it is selected as default from admin.</p>
  
  <p>Or is there any way to add some readymade widget to switch stores (Store Switcher). The theme I am using does not have this feature to auto populate store switcher as default Magento Luma theme provides.</p>