I am using Magento 2.1.7 and want to programatically load a specific store view on my multi-site based on what country a user is in when they arrive on our website. However in Magento 2 I am not sure how to do this. I tried doing the below. However it does not seem to work?? Any suggestions?
I have the below code
//lets redirect user to a country specific store based on where they are from
$myipaddressis = $_SERVER['REMOTE_ADDR'];
$mycountryis = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
if($mycountryis =='DE')
{
//$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->setCurrentStore(1);
}
if($mycountryis =='GB')
{
//$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->setCurrentStore(2);
}