...
Code Block |
---|
composer require "creativestyle/magesuite-geolocation" ^1.0.0 |
This extension requires a custom second extension that contains MaxMind GeoIP2 Country Database file.
We’re not able to provide such an extension because of the file licensing.
Such extension must implement \MageSuite\Geolocation\Model\Asset\DatabasePathResolverInterface
interface that returns absolute file path to mmdb file, an example implementation below:
etc/di.xml
:
Code Block | ||
---|---|---|
| ||
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MageSuite\Geolocation\Model\Asset\DatabasePathResolverInterface"
type="MageSuite\GeolocationDatabase\Model\Asset\DatabasePathResolver" />
</config> |
Code Block | ||
---|---|---|
| ||
<?php
namespace MageSuite\GeolocationDatabase\Model\Asset;
class DatabasePathResolver implements \MageSuite\Geolocation\Model\Asset\DatabasePathResolverInterface
{
/**
* @inheritDoc
*/
public function getPath() {
return realpath(__DIR__ . '/GeoLite2-Country.mmdb');
}
}
|
Admin settings
There are no admin settings, the module is active when installed.
Backend
Backend helper
If geolocation is needed inside BE logic then \MageSuite\Geolocation\Service\CountryResolverInterface
should be injected into class constructor.
...
A custom IP address can be passed to resolve
method, otherwise, IP from server headers will be taken into account.
...
Frontend
...
Two-letter ISO country code of a user (or empty string when IP address location was not detected) can be fetched by javascript in the following way:
...