GEO location

This page contains information about ASA 2 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 ASA 2‘s Internationalization (i18n) feature.

Asa2_Module_Premium_GeoIp::getUserCountryIsoCode()

Description

This method retrieves the user’s ISO country code.

Note

This method considers the i18n demo user ID.

Code

<?php
if (class_exists('Asa2_Module_Premium_GeoIp')) {
    $userCountryCode = Asa2_Module_Premium_GeoIp::getUserCountryIsoCode();
}

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
if (class_exists('Asa2_Module_Premium_GeoIp')) {
    $userCountryCode = Asa2_Module_Premium_GeoIp::getUserCountryIsoCode();
}

// check if $userCountryCode could be set and if it is a supported Amazon API country
// otherwise set it to the default store country, configed on |asa2|'s setup page
if (!isset($userCountryCode) || !Asa2_Service_Stores::isSupportedCountryCode($userCountryCode)) {
    $userCountryCode = Asa2_Service_Amazon_Credentials::getDefaultCountryStore();
}

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

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

Asa2_Module_Premium_GeoIp::getStoreSafeUserCountryIsoCode()

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 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 ASA 2‘ setup page.

Note

This method considers the i18n demo user ID.

Code

<?php
if (class_exists('Asa2_Module_Premium_GeoIp')) {
    $userCountryCode = Asa2_Module_Premium_GeoIp::getStoreSafeUserCountryIsoCode();
}

Parameters

This method has no parameters.

Result

Type: String

A country ISO code. Only countries supported by the 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
if (class_exists('Asa2_Module_Premium_GeoIp')) {
    $userCountryCode = Asa2_Module_Premium_GeoIp::getStoreSafeUserCountryIsoCode();
}

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

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

Asa2_Module_Premium_GeoIp::getData()

Description

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

Note

This method considers the i18n demo user ID.

Code

<?php
if (class_exists('Asa2_Module_Premium_GeoIp')) {
    $userCountryCode = Asa2_Module_Premium_GeoIp::getUserData();
}

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] => 德国
                )

        )

)