Type
magento2-module
Magento 2 module providing basic Geo IP detection.
magento2-module
MIT
None
None
None
None
None
Magento 2 module providing basic Geo IP detection.
$ curl https://<magento site>/rest/V1/countryCode
"NL"
<?php
namespace Acme\Component;
use Mooore\GeoIp\Api\CountryCodeInterface;
class SomeComponent
{
/**
* @var \Mooore\GeoIp\Api\CountryCodeInterface
*/
private $countryCode;
public function __construct(CountryCodeInterface $countryCode)
{
$this->countryCode = $countryCode;
}
public function execute(): void
{
//output: Country is NL
echo sprintf('Country is %s', $this->countryCode->get());
}
}
composer require mooore/magento2-module-geoip
bin/magento setup:upgrade
This module has a fallback reliance on several inputs:
1. GeoIP variable GEOIP_COUNTRY_CODE
.
2. GeoIP2 variable COUNTRY_CODE
.
3. Cloudflare header CF-IPCountry
.
4. IpInfo.io API.
To be able to fall back on IpInfo.io, follow these steps: 1. Have an account at ipinfo.io (usage is free for 50k requests per month). 2. Have the ipinfo.io API key. 3. Configure it in the Magento 2 backend (Advanced -> System -> GeoIP):