diff --git a/core/components/storelocator/elements/snippets/snippet.storelocator.php b/core/components/storelocator/elements/snippets/snippet.storelocator.php index 17fe620..4a9c3be 100644 --- a/core/components/storelocator/elements/snippets/snippet.storelocator.php +++ b/core/components/storelocator/elements/snippets/snippet.storelocator.php @@ -39,12 +39,14 @@ $markerImage = $modx->getOption('markerImage', $scriptProperties, '0'); $sortDir = $modx->getOption('sortDir', $scriptProperties, 'ASC'); $limit = $modx->getOption('limit', $scriptProperties, 0); +$startResults = $modx->getOption('startResults', $scriptProperties, 0); // Templating parameters $formTpl = $modx->getOption('formTpl', $scriptProperties, 'sl.form'); $storeRowTpl = $modx->getOption('storeRowTpl', $scriptProperties, 'sl.storerow'); $storeInfoWindowTpl = $modx->getOption('storeInfoWindowTpl', $scriptProperties, 'sl.infowindow'); $noResultsTpl = $modx->getOption('noResultsTpl', $scriptProperties, 'sl.noresultstpl'); +$emptyResultsTemplate = $modx->getOption('emptyResultsTemplate', $scriptProperties, 'emptyResultsTemplate'); // Developers templating parameters $scriptWrapperTpl = $modx->getOption('scriptWrapperTpl', $scriptProperties, 'sl.scriptwrapper'); @@ -77,9 +79,11 @@ $query->sortby('sort', $sortDir); $query->limit($limit); +$totalStores = $modx->getCount('slStore', $query); $stores = $modx->getCollection('slStore', $query); $storeListOutput = ''; $i = 0; +$matchedStores = 0; foreach($stores as $store) { if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { @@ -108,6 +112,7 @@ $resourceArray, array( 'store' => $store->toArray(), + 'totalStores' => $totalStores, 'onclick' => 'storeLocatorMap.setCenter(new google.maps.LatLng('.$store->get('latitude').', '.$store->get('longitude').')); storeLocatorMap.setZoom('.$storeZoom.');' ) )); @@ -116,7 +121,8 @@ $infoWindowOutput = $storeLocator->getChunk($storeInfoWindowTpl, array_merge( $resourceArray, array( - 'store' => $store->toArray() + 'store' => $store->toArray(), + 'totalStores' => $totalStores ) )); @@ -130,9 +136,10 @@ )); $i++; + $matchedStores++; } } - + // Nothing is found if ($i == 0) { $storeListOutput = $storeLocator->getChunk($noResultsTpl); @@ -140,12 +147,22 @@ $locatorFormOutput = $storeLocator->getChunk($formTpl, array( 'query' => str_replace(array('[', ']'), '', $_REQUEST['query']), - 'radius' => isset($_REQUEST['radius']) ? $_REQUEST['radius'] : $defaultRadius + 'radius' => isset($_REQUEST['radius']) ? $_REQUEST['radius'] : $defaultRadius, + 'totalStores' => $totalStores, + 'matchedStores' => $matchedStores )); +$emptyStartResults = 0; +//check for startResult +if (strtolower($_SERVER['REQUEST_METHOD']) != 'post' && $startResults == 0) { + $emptyStartResults = 1; +} // Parse output to place holders $modx->toPlaceHolders(array( 'map' => '
', 'storeList' => $storeListOutput, - 'form' => $locatorFormOutput -), 'StoreLocator'); \ No newline at end of file + 'form' => $locatorFormOutput, + 'totalStores' => $totalStores, + 'emptyStartResult' => $emptyStartResults, + 'matchedStores' => $matchedStores +), 'StoreLocator');