Question

I'd like to configure the Magento site to be able to recognize the default language and location of the user and display the site in that language and with appropriate localization.

For example:

A user from Russia with the Russian language as default will go directly to the Russian Language website with Rubles as the default currency and prices.

Is this possible? If so how?

Was it helpful?

Solution

GeoIP and Store Views will help you solve this issue.

GeoIP You can use a provider like MaxMind for your GeoIP database (or load it as a web server module that adds the country in the header).

Based on the IP address you can redirect the customer to the proper Store View (check the link generated by the store view switcher.

Store Views

Russian should be a Store View. Check the store view switcher to see what is the link you need to use for your customers.

After redirection you can set a cookie to associate the customer with the store view.

OTHER TIPS

There is a Magento GeoIP extension (written by me) which downloads latest MaxMind data file and periodically updates it.

I suggest hooking into controller_front_init_before event. You can use the following code to check get the ISO 3166-1 code of visitor's country and then redirect him to corespondent store view if you have one:

$geoIP = Mage::getSingleton('geoip/country');
$code = $geoIP->getCountry();

/*
 * Check if store view for this country/language exists and it is not a current store view. 
 * If so do a redirect.
 * You can also take a language from user agent into consideration.
 */

The detailed article about using this extension can be found here.

Another thing to look at is GEO IP.

Couple of lines of code will give you the users country code, which you can switch based on that.

But note that you will have issues using any redirection based code if you are using the same store with Enterprise Edition and Full Page Cache as the first page hit is cached.

take a look at http://www.thefutureoftheweb.com/blog/use-accept-language-header if you can program. You could make a switch in the index.php loading the storeview appropriate for the language.

Another option is to use PHP's auto_prepend configuration. This will cause all scripts handled by PHP to run the script before the actual requested script runs, but after .htaccess (if you're using that).

This approach combined with some of the other suggestions (e.g. using MaxMind for geo location data and store views for specific regions) can result in a rather clean approach.

If you're running a version of Magento >= 1.4, the default store code can be configured by setting the $_SERVER['MAGE_RUN_CODE'] value.

In either the .htaccess file or apache's configuration add the following:

php_value auto_prepend_file /var/www/mystore/path/to/script.php

In your script.php perform any necessary business logic and set the appropriate store code:

<?php
if (get_ip_location($_SERVER['REMOTE_ADDR']) == 'uk') {
    $_SERVER['MAGE_RUN_CODE'] = 'store_code_uk';
} else {
    $_SERVER['MAGE_RUN_CODE'] = 'store_code_us';
}

One thing to note is that this will apply for all PHP files requested, so you'll need to keep that in mind.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top