mooore / magento2-module-geoip
Magento 2 module providing basic Geo IP detection.
Installs: 26 144
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 1
Open Issues: 0
Type:magento2-module
Requires
- magento/framework: ^102.0|^103.0
- psr/log: ^1.0
This package is auto-updated.
Last update: 2024-11-10 16:42:12 UTC
README
Magento 2 module providing basic Geo IP detection.
API
REST
$ curl https://<magento site>/rest/V1/countryCode "NL"
PHP
<?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()); } }
Installation
composer require mooore/magento2-module-geoip bin/magento setup:upgrade
Configuration
This module has a fallback reliance on several inputs:
- GeoIP variable
GEOIP_COUNTRY_CODE
. - GeoIP2 variable
COUNTRY_CODE
. - Cloudflare header
CF-IPCountry
. - IpInfo.io API.
To be able to fall back on IpInfo.io, follow these steps:
- Have an account at ipinfo.io (usage is free for 50k requests per month).
- Have the ipinfo.io API key.
- Configure it in the Magento 2 backend (Advanced -> System -> GeoIP):