From cb852ace0bebec46cf3afebab572b4b584ea7019 Mon Sep 17 00:00:00 2001 From: Artem Serbulenko Date: Sat, 5 Sep 2026 23:16:40 +0300 Subject: [PATCH 1/2] add product search --- upload/admin/controller/catalog/product.php | 36 ++++++++ .../admin/language/en-gb/catalog/product.php | 1 + .../admin/language/ru-ru/catalog/product.php | 1 + upload/admin/model/catalog/product.php | 86 +++++++++++++++++++ .../view/template/catalog/product_list.twig | 24 +++++- 5 files changed, 146 insertions(+), 2 deletions(-) diff --git a/upload/admin/controller/catalog/product.php b/upload/admin/controller/catalog/product.php index f50f3286..2b7d5529 100644 --- a/upload/admin/controller/catalog/product.php +++ b/upload/admin/controller/catalog/product.php @@ -116,6 +116,10 @@ public function edit() { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } + if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); } @@ -208,6 +212,10 @@ public function delete() { if (isset($this->request->get['filter_name'])) { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); @@ -294,6 +302,10 @@ public function copy() { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } + if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); } @@ -366,6 +378,12 @@ protected function getList() { $filter_name = ''; } + if (isset($this->request->get['filter_search'])) { + $filter_search = $this->request->get['filter_search']; + } else { + $filter_search = ''; + } + if (isset($this->request->get['filter_model'])) { $filter_model = $this->request->get['filter_model']; } else { @@ -523,6 +541,10 @@ protected function getList() { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } + if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); } @@ -600,6 +622,7 @@ protected function getList() { $filter_data = array( 'filter_name' => $filter_name, + 'filter_search' => $filter_search, 'filter_model' => $filter_model, 'filter_price' => $filter_price, 'filter_price_min'=> $filter_price_min, @@ -686,6 +709,10 @@ protected function getList() { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } + if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); } @@ -757,6 +784,10 @@ protected function getList() { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } + if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); } @@ -823,6 +854,7 @@ protected function getList() { $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); $data['filter_name'] = $filter_name; + $data['filter_search'] = $filter_search; $data['filter_model'] = $filter_model; $data['filter_price'] = $filter_price; $data['filter_price_min'] = $filter_price_min; @@ -893,6 +925,10 @@ protected function getForm() { $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); } + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode(html_entity_decode($this->request->get['filter_search'], ENT_QUOTES, 'UTF-8')); + } + if (isset($this->request->get['filter_model'])) { $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); } diff --git a/upload/admin/language/en-gb/catalog/product.php b/upload/admin/language/en-gb/catalog/product.php index 786f465f..26a3091a 100644 --- a/upload/admin/language/en-gb/catalog/product.php +++ b/upload/admin/language/en-gb/catalog/product.php @@ -21,6 +21,7 @@ $_['column_status'] = 'Status'; $_['column_noindex'] = 'Index'; $_['column_action'] = 'Action'; +$_ ['entry_search'] = 'Search'; $_['entry_name'] = 'Product Name'; $_['entry_description'] = 'Description'; $_['entry_meta_title'] = 'Meta Tag Title'; diff --git a/upload/admin/language/ru-ru/catalog/product.php b/upload/admin/language/ru-ru/catalog/product.php index 3673d88a..d6b71b72 100644 --- a/upload/admin/language/ru-ru/catalog/product.php +++ b/upload/admin/language/ru-ru/catalog/product.php @@ -25,6 +25,7 @@ $_['column_status'] = 'Статус'; $_['column_noindex'] = 'Индексация'; $_['column_action'] = 'Действие'; +$_['entry_search'] = 'Поиск'; $_['entry_name'] = 'Название товара'; $_['entry_description'] = 'Описание'; $_['entry_description_mini'] = ''; diff --git a/upload/admin/model/catalog/product.php b/upload/admin/model/catalog/product.php index e16068cb..0c34cf56 100644 --- a/upload/admin/model/catalog/product.php +++ b/upload/admin/model/catalog/product.php @@ -441,6 +441,49 @@ public function getProducts($data = array()) { $sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'"; } + if (!empty($data['filter_search'])) { + $sql .= " AND ("; + + $implode = []; + + $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search']))); + + foreach ($words as $word) { + $implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "%'"; + } + + if ($implode) { + $sql .= " " . implode(" AND ", $implode) . ""; + } + + if (!empty($data['filter_description'])) { + $sql .= " OR pd.description LIKE '%" . $this->db->escape($data['filter_search']) . "%'"; + } + + $sql .= " OR "; + + $implode = []; + + $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search']))); + + foreach ($words as $word) { + $implode[] = "pd.tag LIKE '%" . $this->db->escape($word) . "%'"; + } + + if ($implode) { + $sql .= " " . implode(" AND ", $implode) . ""; + } + + $sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= ")"; + } + if (!empty($data['filter_model'])) { $sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'"; } @@ -789,6 +832,49 @@ public function getTotalProducts($data = array()) { $sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'"; } + if (!empty($data['filter_search'])) { + $sql .= " AND ("; + + $implode = []; + + $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search']))); + + foreach ($words as $word) { + $implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "%'"; + } + + if ($implode) { + $sql .= " " . implode(" AND ", $implode) . ""; + } + + if (!empty($data['filter_description'])) { + $sql .= " OR pd.description LIKE '%" . $this->db->escape($data['filter_search']) . "%'"; + } + + $sql .= " OR "; + + $implode = []; + + $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_search']))); + + foreach ($words as $word) { + $implode[] = "pd.tag LIKE '%" . $this->db->escape($word) . "%'"; + } + + if ($implode) { + $sql .= " " . implode(" AND ", $implode) . ""; + } + + $sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= ")"; + } + if (!empty($data['filter_model'])) { $sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'"; } diff --git a/upload/admin/view/template/catalog/product_list.twig b/upload/admin/view/template/catalog/product_list.twig index 5e3f5c7c..34c84d8a 100644 --- a/upload/admin/view/template/catalog/product_list.twig +++ b/upload/admin/view/template/catalog/product_list.twig @@ -40,6 +40,15 @@

{{ text_filter }}

+
+ +
+ +
+ +
+
+
@@ -269,6 +278,12 @@ url += '&filter_name=' + encodeURIComponent(filter_name); } + var filter_search = $('input[name=\'filter_search\']').val(); + + if (filter_search) { + url += '&filter_search=' + encodeURIComponent(filter_search); + } + var filter_model = $('input[name=\'filter_model\']').val(); if (filter_model) { @@ -297,7 +312,7 @@ if (filter_quantity_max) { url += '&filter_quantity_max=' + encodeURIComponent(filter_quantity_max); - } + } var filter_status = $('select[name=\'filter_status\']').val(); @@ -341,7 +356,12 @@ $('button[form=\'form-product\']').on('click', function(e) { $('#form-product').attr('action', $(this).attr('formaction')); }); - + + $('#button-clear-input-search').on('click',function(){ + $('input[name=\'filter_search\']').val(''); + $('#button-filter').trigger('click'); + }); + $('input[name=\'filter_name\']').autocomplete({ 'source': function(request, response) { $.ajax({ From f3393f5be8b637d5cb474affa9187a1491465290 Mon Sep 17 00:00:00 2001 From: Artem Serbulenko Date: Sun, 6 Sep 2026 16:01:22 +0300 Subject: [PATCH 2/2] like % --- upload/admin/model/catalog/product.php | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/upload/admin/model/catalog/product.php b/upload/admin/model/catalog/product.php index 0c34cf56..3a0ed126 100644 --- a/upload/admin/model/catalog/product.php +++ b/upload/admin/model/catalog/product.php @@ -474,13 +474,13 @@ public function getProducts($data = array()) { $sql .= " " . implode(" AND ", $implode) . ""; } - $sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.sku) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.upc) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.ean) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.jan) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.isbn) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.mpn) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; $sql .= ")"; } @@ -865,13 +865,13 @@ public function getTotalProducts($data = array()) { $sql .= " " . implode(" AND ", $implode) . ""; } - $sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; - $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "'"; + $sql .= " OR LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.sku) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.upc) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.ean) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.jan) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.isbn) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; + $sql .= " OR LCASE(p.mpn) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_search'])) . "%'"; $sql .= ")"; }