Skip to content

Developer notes

The core add-ons choose their scripts from their provider setting. On every request of an area set to OpenStreetMap, the before_dispatch hook changes that value in memory only (Registry::set(..., true), never written to the database or the settings cache):

  • geo_maps → kv_osm: the core loads its generic map scripts (maps.js, code.js, locate.js, func.js) and no Google/Yandex file; js/addons/kv_maps_geo_cost_saver/osm.js registers the OpenStreetMap handlers with the core plugin API ($.ceGeoMap('setHandlers'), $.ceGeoCode('setHandlers'), $.ceGeoLocate('setHandlers')).
  • vendor_locations → google: its address field only renders for Google, so its generic Google flow stays and osm_vendor_locations.js replaces its three plugins ($.ceGeolocate, $.fn.ceGeocomplete, $.fn.ceGeomap). No Google script is called.

Leaflet 1.9.4 and Leaflet.markercluster 1.5.3 ship in js/addons/kv_maps_geo_cost_saver/lib/ (BSD-2 and MIT licences included) and are loaded only when the first map opens.

Path Purpose
app/addons/kv_maps_geo_cost_saver/addon.xml Settings, tables
app/addons/kv_maps_geo_cost_saver/func.php Hook handlers, settings info handlers
Tygh/Addons/KvMapsGeoCostSaver/Config.php Settings, licence gate (Config::isOn())
Tygh/Addons/KvMapsGeoCostSaver/Provider.php In-memory provider switch
Tygh/Addons/KvMapsGeoCostSaver/Geocoder.php Nominatim / Photon client, cache, limits
Tygh/Addons/KvMapsGeoCostSaver/Normalizer.php One location format for both services, place ids
Tygh/Addons/KvMapsGeoCostSaver/Throttle.php One request at a time per public service (lock file)
Tygh/Addons/KvMapsGeoCostSaver/Stats.php Daily counters, rate buckets
Tygh/Addons/KvMapsGeoCostSaver/Savings.php Savings estimate, cache figures
Tygh/Addons/KvMapsGeoCostSaver/PreGeocode.php Missing coordinates of store locations and vendors
Tygh/Addons/KvMapsGeoCostSaver/Endpoint.php, View.php, Maintenance.php JSON endpoint and beacon, page script data, cron run
Tygh/Addons/KvMapsGeoCostSaver/License/ Domain-bound licence client
Tygh/Addons/KvMapsGeoCostSaver/Upgrade/Synchronizer.php Self-healing upgrades
controllers/frontend/kv_maps_geo_cost_saver.php geocode, beacon (GET, no_session=Y)
controllers/backend/kv_maps_geo_cost_saver.php Dashboard, tools, cron
controllers/backend/kv_maps_geo_cost_saver_geo.php geocode for administrators and vendors
schemas/gdpr/klaro_config.post.php Cookie consent service kv_osm_maps
schemas/full_page_cache/varnish.post.php The add-on tables are never cache tags
design/backend/templates/addons/kv_maps_geo_cost_saver/components/scripts.tpl Page configuration and scripts (storefront includes it as backend:)
js/addons/kv_maps_geo_cost_saver/core.js Lazy maps, bot filter, deferred detection, beacon, helpers
Table Columns
?:kv_mgcs_cache cache_key (sha1), kind (search, reverse, suggest), query, lang, result (JSON), created_at, expires_at, hits
?:kv_mgcs_stats day (YYYYMMDD), metric, value
?:kv_mgcs_pregeo object_type (store, vendor), object_id, status (D done, F failed), attempts, message, updated_at
?:kv_mgcs_rate bucket (sha1), window_start, hits

index.php?dispatch=kv_maps_geo_cost_saver.geocode&type=<type>&lang=<code>&no_session=Y (storefront) and admin.php?dispatch=kv_maps_geo_cost_saver_geo.geocode&type=<type> (admin, vendor panel) answer JSON {status, source, results}:

type Parameters Answer
search q, limit Addresses
suggest q, limit Address suggestions (Photon)
reverse lat, lng, kind (address, locality, state, country) The place at the coordinates
place place_id A place id issued by the add-on
locate The visitor’s country from the IP address (CS-Cart’s GeoLite2 database)

status: ok, empty, invalid, limited (a limit or the one-request-per-second queue), error, disabled. Each result has place_id, lat, lng, formatted_address, type, country, country_text, state, state_text, state_code, locality, locality_text, route, postal_code, street_number (with _text variants), viewport, locality_place_id, country_place_id.

Place ids carry their coordinates: osm:<N|W|R><osm id>:<lat>,<lng>:<country|state|locality|address>, so a stored place can always be looked up again.

Server side: geo_cache, geo_upstream, geo_fail, geo_limited, suggest_cache, suggest_upstream, locate_free, pregeo_done, upstream_total. From the page (one GET per page view, capped per value and per visitor): map_osm, map_core, map_lazy, map_bot, locate_deferred, locate_free.

Tygh.kv_mgcs is printed after the script bundle; core.js starts when it is assigned. Providers register through Tygh.kvMgcsReady(function (K) { ... }). K.loadLeaflet(), K.api(type, params), K.autocomplete($input, options) and K.pinIcon(L) are available to themes. For tests with automation tools, ?kv_mgcs_human=1 (stored in localStorage) disables the bot filter for that browser.

Hook Use
before_dispatch In-memory provider switch for the area
dispatch_before_display Page script data ($kv_mgcs)

Template hooks: index:scripts (post, storefront and admin), index:styles (post).

The page output is the same for every visitor (settings only). Everything per visitor runs in the browser and calls the endpoint with no_session=Y, so guests never get a session from the add-on. The add-on’s tables are excluded from the cache tags, so cache and counter writes never purge pages.

Config::isOn() = enabled and License\Client::isActive(). It gates the provider switch, the page scripts, the endpoint, the beacon and the coordinate jobs. The dashboard and the data always work.