Reputation: 783
I am using the maxmind geo ip database and I have the following code on my index.php so as to redirect users from china to the chinese store of the site
Mage::app();
$geoIP = Mage::getSingleton('geoip/country');
$country = $geoIP->getCountry();
if(strcmp($country, 'CN')== 0)
{
$mageRuntType = 'store';
$mageRunCode = 'cn';
}
The problem is if a user visits the site from china and changes the store to the english store manually via the store changer on the site and then visits another page it again goes back to the chinese store. How do I fix this?
Upvotes: 0
Views: 280
Reputation: 15216
The easiest way is to set a cookie that expires along with the session when you redirect to the CN
store the first time.
Then, if that cookie is set don't do the redirect. Something like:
if (!isset($_COOKIE['redirected'])){
Mage::app();
$geoIP = Mage::getSingleton('geoip/country');
$country = $geoIP->getCountry();
if(strcmp($country, 'CN')== 0)
{
$mageRuntType = 'store';
$mageRunCode = 'cn';
setcookie('redirected', 1, 0)
}
}
Upvotes: 2