Skip to content
  1. Extras
  2. GeoLocation2
  3. Integration

Integration

Manager

Components → GeoLocation2 tabs:

TabTableContent
Countriesgl_countriesISO, timezone, default country
Regionsgl_regionsRegion linked to country
Citiesgl_citiesCity, region, coordinates, default flag
Datagl_dataContacts, address, image, alt name for a city

CSV import and export are available in the manager UI.

Data model

gl_countries
  └── gl_regions
        └── gl_cities
              └── gl_data (0..n per city)

User session ($_SESSION['gl2'], key from service):

Session fieldPurpose
city_idID from gl_cities
confirmedUser confirmed or picked a city
dismissedModal closed without choice (when applicable)
csrfToken for POST to action.php

PHP service

php
/** @var \GeoLocation2\Service\GeoLocation2 $gl2 */
$gl2 = $modx->services->get('GeoLocation2');

$cityId = $gl2->getCurrentCityId();
$state = $gl2->getSessionState();
$gl2->setCity($cityId, true);

See core/components/geolocation2/src/Service/ for methods and events.

SxGeo

Database file:

text
assets/components/geolocation2/vendor/sypexgeo/data/SxGeoCity.dat

With geolocation2_detect_method = sxgeo, first visit without session: IP → SxGeo → match against gl_cities.

SxGeo update

CLI (from MODX root):

bash
php assets/components/geolocation2/bin/update-sxgeo.php

Scheduler (MODX 3): task geolocation2_update_sxgeo. Enable geolocation2_sxgeo_auto_update and set geolocation2_sxgeo_update_interval_days.

PHP-FPM restart is not required: new .dat is picked up on next SxGeo read.

Fenom and placeholders

Current city in template:

fenom
{$_modx->runSnippet('!GeoLocation2Current', ['tpl' => 'tpl.GeoLocation2.current'])}
modx
[[!GeoLocation2Current? &tpl=`tpl.GeoLocation2.current`]]

Chunk placeholders depend on tpl; tpl.GeoLocation2.current usually exposes [[+city_name]], [[+region_name]], [[+country_name]].

miniShop and delivery

GeoLocation2 does not change the cart. Typical flow:

  1. User picks a city in the modal.
  2. Pass city_id from session to a delivery snippet or order options.
  3. Use gl_data for phone/address of a pickup point in the selected city.

Package chunks

ChunkPurpose
tpl.GeoLocation2.currentCurrent city (modal trigger)
tpl.GeoLocation2.modalBootstrap 5 modal markup
tpl.GeoLocation2.modal.itemCity row in modal list
tpl.GeoLocation2.itemRow in GeoLocation2 list
tpl.GeoLocation2.locationSxGeo lookup output
tpl.GeoLocation2.data.itemgl_data table row
tpl.GeoLocation2.data.currentgl_data card for current city

See Web API and snippets.