Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichaykin/667749f19061803edb35694bcccb07fe to your computer and use it in GitHub Desktop.
Save ichaykin/667749f19061803edb35694bcccb07fe to your computer and use it in GitHub Desktop.
diff --git a/app/addons/store_locator/controllers/frontend/store_locator.php b/app/addons/store_locator/controllers/frontend/store_locator.php
index aaa5fdebc0..a3eef7cc99 100644
--- a/app/addons/store_locator/controllers/frontend/store_locator.php
+++ b/app/addons/store_locator/controllers/frontend/store_locator.php
@@ -77,7 +77,6 @@ if ($mode == 'search') {
'page_size' => 10,
'page' => 1,
'status' => ObjectStatuses::ACTIVE,
- 'without_warehouses' => true,
], $_REQUEST);
list($cities, $params) = fn_get_store_location_cities($params);
diff --git a/app/addons/store_locator/func.php b/app/addons/store_locator/func.php
index 60a9d78973..76b38ad645 100644
--- a/app/addons/store_locator/func.php
+++ b/app/addons/store_locator/func.php
@@ -356,7 +356,6 @@ function fn_get_store_location_cities(array $params = [])
'company_id' => null,
'lang_code' => CART_LANGUAGE,
'total_items' => 0,
- 'without_warehouses' => false,
], $params);
if ($params['page_size'] && !$params['items_per_page']) {
@@ -379,9 +378,24 @@ function fn_get_store_location_cities(array $params = [])
$condition['q'] = db_quote('descriptions.city LIKE ?l', '%' . $params['q'] . '%');
}
- if ($params['without_warehouses']) {
- $condition['without_warehouses'] = db_quote('locations.store_type != ?s', 'W');
- }
+ /**
+ * Changes request params before store location cities selecting
+ *
+ * @param array<string, null|int|string> $params Store location cities search params
+ * @param array<string, string> $condition Request condition
+ *
+ * @psalm-param array{
+ * page: int,
+ * page_size: int,
+ * items_per_page: int|null,
+ * q: null|string,
+ * status: null|string,
+ * company_id: null|int,
+ * lang_code: string,
+ * total_items: int
+ * } $params
+ */
+ fn_set_hook('get_store_location_cities', $params, $condition);
$cities = db_get_fields(
'SELECT descriptions.city AS city' .
diff --git a/app/addons/warehouses/controllers/frontend/store_locator.pre.php b/app/addons/warehouses/controllers/frontend/store_locator.pre.php
new file mode 100644
index 0000000000..b750d2dea0
--- /dev/null
+++ b/app/addons/warehouses/controllers/frontend/store_locator.pre.php
@@ -0,0 +1,19 @@
+<?php
+/***************************************************************************
+ * *
+ * (c) 2004 Vladimir V. Kalynyak, Alexey V. Vinokurov, Ilya M. Shalnev *
+ * *
+ * This is commercial software, only users who have purchased a valid *
+ * license and accept to the terms of the License Agreement can install *
+ * and use this program. *
+ * *
+ ****************************************************************************
+ * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE *
+ * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. *
+ ****************************************************************************/
+
+defined('BOOTSTRAP') or die('Access denied');
+
+if ($mode === 'get_cities_list') {
+ $_REQUEST['without_warehouses'] = true;
+}
diff --git a/app/addons/warehouses/func.php b/app/addons/warehouses/func.php
index fc35889970..8404bb406e 100644
--- a/app/addons/warehouses/func.php
+++ b/app/addons/warehouses/func.php
@@ -2547,3 +2547,30 @@ function fn_warehouses_load_products_features_variants_pre(&$variation_products)
/** @var array<array-key, array<array-key, int|string|bool>> $variation_products */
$variation_products = $manager->fetchProductsWarehousesAmountsByDestination($variation_products, $destination_id, $storefront_id);
}
+
+/**
+ * The `get_store_location_cities` hook handler.
+ *
+ * Action performed:
+ * - Adds a condition for the without_warehouses parameter.
+ *
+ * @param array<string, null|int|string> $params Store location cities search params
+ * @param array<string, string> $condition Search conditions
+ *
+ * @psalm-param array{
+ * page: int,
+ * page_size: int,
+ * items_per_page: int|null,
+ * q: null|string,
+ * status: null|string,
+ * company_id: null|int,
+ * lang_code: string,
+ * total_items: int
+ * } $params
+ */
+function fn_warehouses_get_store_location_cities(array $params, array &$condition): void
+{
+ if (!empty($params['without_warehouses'])) {
+ $condition['without_warehouses'] = db_quote('locations.store_type != ?s', 'W');
+ }
+}
diff --git a/app/addons/warehouses/init.php b/app/addons/warehouses/init.php
index c7d4471f15..11e37b9d69 100644
--- a/app/addons/warehouses/init.php
+++ b/app/addons/warehouses/init.php
@@ -62,5 +62,6 @@ fn_register_hooks(
'master_products_reindex_storefront_min_price',
'change_order_status_before_update_product_amount',
'get_product_amount_post',
- 'load_products_features_variants_pre'
+ 'load_products_features_variants_pre',
+ 'get_store_location_cities'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment