GEO location

This page contains information about ASA2 PHP functions you can use in your scripts to determine the user’s origin and related info about Amazon stores. These functions get used by ASA2’s Internationalization (i18n) feature.

Asa2_Module_Premium_GeoIp::getUserCountryIsoCode()

Deprecated Asa2_Module_Premium_GeoIp::getUserCountryIsoCode()

Use asa2_i18n_get_user_country_iso_code() instead.

asa2_i18n_get_user_country_iso_code()

Description

This method retrieves the user’s ISO country code.

Note

This method considers the i18n demo user ID.

API documentation

Check the API documentation page for more details.

ASA2 API documentation

Code

<?php
$userCountryCode = asa2_i18n_get_user_country_iso_code();

Parameters

This method has no parameters.

Result

Type: String

A country ISO code.

For example:

  • “DE” for Germany

  • “FR” for France

  • “US” for United States

Examples

This example renders a collection based on the user’s country of origin.

<?php
$userCountryCode = asa2_i18n_get_user_country_iso_code();

// check if $userCountryCode is a supported Amazon API country
// otherwise set it to the default store country, configed on |asa2|'s setup page
if (!asa2_is_supported_country_code($userCountryCode)) {
    $userCountryCode = asa2_get_default_country_code();
}

// build the collection name
$collectionName = 'blu_ray_movies_' . $userCountryCode;

// display the collection if it exists with a custom template
if (asa2_collection_exists($collectionName)) {
    echo asa2_render_collection($collectionName, array(
        'tpl' => 'blu_ray_movies_collection'
    ));
}

Asa2_Module_Premium_GeoIp::getStoreSafeUserCountryIsoCode()

Deprecated Asa2_Module_Premium_GeoIp::getStoreSafeUserCountryIsoCode()

Use asa2_i18n_get_store_safe_user_country_iso_code() instead.

asa2_i18n_get_store_safe_user_country_iso_code()

Description

This method retrieves an ISO country code which is the best match for an Amazon store related to the user’s origin. If the country is one of the countries supported by the Amazon PA API, it will be this country’s ISO code. Otherwise the method considers the i18n country mapping. So if the user’s is Andorra for example, the method will return “ES” for Spain. If even the i18n coutnry mapping will not provide a result, the method will return the default country configured on ASA2’ setup page.

Note

This method considers the i18n demo user ID.

API documentation

Check the API documentation page for more details.

ASA2 API documentation

Code

<?php
$userCountryCode = asa2_i18n_get_store_safe_user_country_iso_code();

Parameters

This method has no parameters.

Result

Type: String

A country ISO code. Only countries supported by the Amazon PA API will be returned.

For example:

  • “DE” for Germany

  • “FR” for France

  • “US” for United States

Examples

This example renders a collection based on the user’s country of origin. With this method you can skip some of the validation steps used in the example of method Asa2_Module_Premium_GeoIp::getUserCountryIsoCode() above.

<?php
$userCountryCode = asa2_i18n_get_store_safe_user_country_iso_code();

// build the collection name
$collectionName = 'blu_ray_movies_' . $userCountryCode;

// display the collection if it exists with a custom template
if (asa2_collection_exists($collectionName)) {
    echo asa2_render_collection($collectionName, array(
        'tpl' => 'blu_ray_movies_collection'
    ));
}

Asa2_Module_Premium_GeoIp::getData()

Deprecated Asa2_Module_Premium_GeoIp::getData()

Use asa2_i18n_get_user_data() instead.

asa2_i18n_get_user_data()

Description

This method retrieves detailed information about the user’s origin country.

Note

This method considers the i18n demo user ID.

API documentation

Check the API documentation page for more details.

ASA2 API documentation

Code

<?php
$userData = asa2_i18n_get_user_data();

Parameters

This method has no parameters.

Result

Type: Array

Example for origin Germany:

Array
(
    [continent] => Array
        (
            [code] => EU
            [geoname_id] => 6255148
            [names] => Array
                (
                    [de] => Europa
                    [en] => Europe
                    [es] => Europa
                    [fr] => Europe
                    [ja] => ヨーロッパ
                    [pt-BR] => Europa
                    [ru] => Европа
                    [zh-CN] => 欧洲
                )

        )

    [country] => Array
        (
            [geoname_id] => 2921044
            [iso_code] => DE
            [names] => Array
                (
                    [de] => Deutschland
                    [en] => Germany
                    [es] => Alemania
                    [fr] => Allemagne
                    [ja] => ドイツ連邦共和国
                    [pt-BR] => Alemanha
                    [ru] => Германия
                    [zh-CN] => 德国
                )

        )

    [registered_country] => Array
        (
            [geoname_id] => 2921044
            [iso_code] => DE
            [names] => Array
                (
                    [de] => Deutschland
                    [en] => Germany
                    [es] => Alemania
                    [fr] => Allemagne
                    [ja] => ドイツ連邦共和国
                    [pt-BR] => Alemanha
                    [ru] => Германия
                    [zh-CN] => 德国
                )

        )

)