yireo / magento2-salesblock2-by-geo
Block transactions based on geo matching
Package info
github.com/yireo/Yireo_SalesBlock2ByGeo
Type:magento2-module
pkg:composer/yireo/magento2-salesblock2-by-geo
Requires
- geoip2/geoip2: ~2.0
- magento/module-customer: ^101.0|^102.0|^103.0
- magento/module-quote: ^101.0
- yireo/magento2-salesblock2: ^2.2
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-24 19:48:02 UTC
README
This module is a helper-module for the Yireo_SalesBlock2 extension, that allows you to block orders from being placed, based on specific rules defined in the Magento Admin Panel.
This specific module allows you to match by a specific geo location.
Installation
To install this module, use the following commands. First, install this module using composer. Note that this step will fail if the Yireo_SalesBlock2 is not installed yet.
composer require yireo/magento2-salesblock2-by-geo
Once this module is installed via composer, you can enable it:
bin/magento module:enable Yireo_SalesBlock2ByGeo
bin/magento setup:upgrade
There are no further steps to take. The Yireo_SalesBlock2 module automatically picks up on things.
Usage
When creating a rule within the SalesBlock extension, this submodule adds a new geolocation rule to block sales by geolocation. Within the Match field, you can add one or more of the following values:
- A two-letter country code, like
NL(ISO 3166-1 alpha-2) - A three-letter country code, like
NLD(ISO 3166-1 alpha-3) - A two-letter continent code with the prefix
continent:, likecontinent:EU(AF,AN,AS,EU,NA,OC,SA) - An exact IP address
Multiple entries are to be separated by commas.
When the location of a visitor can't be determined (for instance a private IP, a missing database or a lookup error), a geo rule does not match. The error is written to the SalesBlock log when logging is enabled.
The rule message that is shown to the customer can use the variables %ip% and %country%. When the rule has no frontend label, a generic message is shown.
Upgrading from 2.x
- A two-letter value is now always a country code. Continent rules need the prefix
continent:(for instancecontinent:EUinstead ofEU), because some continent codes (AF,AS,NA,SA) are also country codes. - The message variable
%geo%has been renamed to%ip%. - The GeoIP v2 database file must be located in the
var/folder of Magento, and is configured with a path relative tovar/.
GeoIP support
You either need to add a GeoIP2 database to your system and configure this extension to use it (preferred), or install GeoIP support into your PHP installation (usually by installing the legacy PHP extension ext-geoip, which might no longer be available for your PHP version).
For the database, register for an account with MaxMind and download the country database (GeoLite2-Country.mmdb or GeoIP2-Country.mmdb). Upload it to the var/ folder of Magento (for instance var/geoip/GeoLite2-Country.mmdb) and configure the path relative to var/ (geoip/GeoLite2-Country.mmdb) in the Magento Admin Panel under Stores > Configuration > Yireo > Yireo SalesBlock. Do not place the database in the pub/ folder.
Client IP detection and reverse proxies
This module reads the client IP from REMOTE_ADDR only. The X-Forwarded-For header can be set to any value by a client, so it is ignored by default, even when Magento core is configured to use it.
When Magento runs behind a reverse proxy (load balancer, CDN, Varnish), add the IP addresses of your proxies to the setting Trusted proxies. When a request comes from a trusted proxy, the rightmost IP in the X-Forwarded-For header that is not a trusted proxy is used as the client IP.