Pregunta

Me gustaría configurar el sitio de Magento a ser capaz de reconocer el idioma predeterminado y la ubicación del usuario y mostrar el sitio en que el lenguaje y con la localización apropiada.

Por ejemplo:

Un usuario de Rusia con la lengua rusa como predeterminado irá directamente a la página web de la lengua rusa con Rublos como la moneda base y los precios.

¿Es esto posible? Si es así, ¿cómo?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top