From 2e8196d7fcaa591f6d950c4fae6b7cfb0d9661ef Mon Sep 17 00:00:00 2001 From: John Cocula Date: Tue, 26 Mar 2019 01:25:33 +0000 Subject: [PATCH 1/4] Added support for stores that already have lat and lng TVs to avoid unneeded geocoding. --- .../elements/snippets/googlestorelocator.snippet.php | 2 ++ .../model/googlestorelocator/googlestorelocator.class.php | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/core/components/googlestorelocator/elements/snippets/googlestorelocator.snippet.php b/core/components/googlestorelocator/elements/snippets/googlestorelocator.snippet.php index f9d5b6b..58196b0 100644 --- a/core/components/googlestorelocator/elements/snippets/googlestorelocator.snippet.php +++ b/core/components/googlestorelocator/elements/snippets/googlestorelocator.snippet.php @@ -16,6 +16,8 @@ // Configuration parameters $config['parents'] = array_unique(explode(',', $modx->getOption('parents', $scriptProperties, $modx->resource->get('id'), true))); +$config['tvname_lat'] = $modx->getOption('tvNameLat', $scriptProperties, 'gslLat', true); +$config['tvname_lng'] = $modx->getOption('tvNameLng', $scriptProperties, 'gslLng', true); $config['tvname_zipcode'] = $modx->getOption('tvNameZipcode', $scriptProperties, 'gslZipcode', true); $config['tvname_city'] = $modx->getOption('tvNameCity', $scriptProperties, 'gslCity', true); $config['tvname_street'] = $modx->getOption('tvNameStreet', $scriptProperties, 'gslStreet', true); diff --git a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php index 4102674..81fb057 100644 --- a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php +++ b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php @@ -18,6 +18,8 @@ public function __construct(MODX $modx, array $config = array()) $this->apikeyServer = $this->modx->getOption('googlestorelocator.apikey_server'); $this->apikeyMap = $this->modx->getOption('googlestorelocator.apikey_map'); $this->parents = $config['parents']; + $this->tvname_lat = $config['tvname_lat']; + $this->tvname_lng = $config['tvname_lng']; $this->tvname_street = $config['tvname_street']; $this->tvname_housenumber = $config['tvname_housenumber']; $this->tvname_zipcode = $config['tvname_zipcode']; @@ -97,6 +99,8 @@ public function getStores() $store = array( 'id' => $item->id, 'name' => $item->pagetitle, + 'lat' => $page->getTVValue($this->tvname_lat), + 'lng' => $page->getTVValue($this->tvname_lng), 'street' => $page->getTVValue($this->tvname_street), 'housenumber' => $page->getTVValue($this->tvname_housenumber), 'zipcode' => $page->getTVValue($this->tvname_zipcode), From fd173ade4f7812e2e82594751b21c84d5519e398 Mon Sep 17 00:00:00 2001 From: John Cocula Date: Tue, 26 Mar 2019 17:03:56 +0000 Subject: [PATCH 2/4] The message should have access to the radius used. --- .../model/googlestorelocator/googlestorelocator.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php index 81fb057..92bea52 100644 --- a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php +++ b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php @@ -242,6 +242,7 @@ public function setLocation($stores) if (!empty($_REQUEST['location'])) { $message = $this->modx->getChunk($this->tpl_message, array( 'address' => $locationData['address'], + 'radius' => $radius, )); $this->modx->toPlaceholders(array( From 11b8d6997062ac39da663f84d5146f7501783154 Mon Sep 17 00:00:00 2001 From: John Cocula Date: Fri, 29 Mar 2019 14:59:29 +0000 Subject: [PATCH 3/4] Add contains operator to where clause to include location if substring is found. --- .../model/googlestorelocator/googlestorelocator.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php index 92bea52..692b27f 100644 --- a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php +++ b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php @@ -309,6 +309,9 @@ public function filterStores($stores, $key, $value, $operator = '<=') $stores = array_filter($stores, function ($var) { switch ($this->operator) { + case 'contains': + return strpos($var[$this->key], $this->value) !== false; + break; case '==': case '=': return ($var[$this->key] == $this->value); From 24838206a953b9d389b95d8d3e9c43197a1293be Mon Sep 17 00:00:00 2001 From: John Cocula Date: Mon, 23 Mar 2020 10:59:45 +0000 Subject: [PATCH 4/4] Updated readme.md with new properties. --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 62fbdcb..9d7ce16 100644 --- a/readme.md +++ b/readme.md @@ -24,6 +24,8 @@ Since the latest version of Google-API: API-KEY(s) are required! Create a API-KE | &tvNameHousenumber | gslHousenumber | Name of the TV holding the Housenumber of the Store. | | &tvNameState | gslState | Name of the TV holding the State of the Store. | | &tvNameCountry | gslCountry | Name of the TV holding the Country of the Store. | +| &tvNameLat | gslLat | Name of the TV holding the Latitude of the Store (to skip geocoding). | +| &tvNameLng | gslLng | Name of the TV holding the Longitude of the Store (to skip geocoding). | | &includeTVs | | Comma-separated list of TVs that should be included in the placeholders available to each store template. Example: "storename,time" will produce the placeholders and . | | &tvPrefix | tv. | Prefix TV property. | | &unit | K | Options: K = kilometers / M = miles / N = nautical | @@ -124,6 +126,7 @@ If you have more than 50 stores the initail rendering of all stores will take a I tested the extra with about 1500 stores. The first rendering took about 4 refreshes and 1 Minute in between every refresh. After that: everything runs smooth. Change a store/resource in the manager will delete this store from the cache and will be rewritten after the next request of the StoreLocation snippet. This won't take long, because it is just rendering the new added or changed stores. If you manually clear the complete site-cache it also clears the GoogleStoreLocator cache and it needs a new rendering of all stores. +If your store resources already have latitude and longitude TVs, specify them with the `&tvNameLat` and `&tvNameLng` properties to skip the overhead of geocoding the addresses. # Upgrading from Version 1.x to 2.x Upgrading from Version 1.x to 2.x needs some little Changes in the propertie-setup.