Magento index.php与Geoip

时间:2013-04-04 14:02:18

标签: magento magento-1.5 geoip

我在index.php中为Magento写了一小段代码,根据Geoip的country_code自动切换store-view。

代码工作正常,但我不是专家,我无法判断我是否有效地追索代码。

我认为最好将countryCode保存到会话中。我知道如何在扩展中执行此操作,但我无法弄清楚如何在index.php中执行此操作。

$geocountryCode = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
$countryList = array("AT","BE","BG","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IE","IT","LV","LT","LU","MT","NL","PL","PT","SK","SI","ES","SE","GB","RO");

    if(!in_array($geocountryCode, $countryList)) {
        $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'int';
        $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

    } else {
        $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default';
        $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
    }

    Mage::run($mageRunCode, $mageRunType);  

致以最诚挚的问候,

雷米

0 个答案:

没有答案