Last active
January 2, 2016 00:09
-
-
Save miguelbalparda/8221903 to your computer and use it in GitHub Desktop.
Change store by location - Magento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ip = $_SERVER["REMOTE_ADDR"];//cant use helper, not loaded yet | |
$location = file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key=<api_key>&format=json&ip='.$ip.''); | |
$location = json_decode($location); | |
$country = $location->countryCode; | |
if(strcmp($country,'CA') == 0) { | |
$mageRunType = 'store'; | |
$mageRunCode = 'en_ca'; | |
} | |
else | |
{ | |
$mageRunType = 'store'; | |
$mageRunCode = 'default'; | |
} | |
Mage::reset(); |
Why not to use maxmind geoip.dat + geoip.inc? At least there is no overhead of third party request.
Agree MagePsycho, this can be combined with geoip but Magento is not loaded at this point, so it should be a plain PHP script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to index.php just before Mage::run($mageRunCode, $mageRunType);