This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
/
advanced_search_result.php
185 lines (143 loc) · 7.02 KB
/
advanced_search_result.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/
require 'includes/application_top.php';
require language::map_to_translation('advanced_search.php');
$error = false;
if ( empty($_GET['keywords'])
&& (empty($_GET['dfrom']) || ($_GET['dfrom'] == DATE_FORMAT_STRING))
&& (empty($_GET['dto']) || ($_GET['dto'] == DATE_FORMAT_STRING))
&& !is_numeric($_GET['pfrom'] ?? null)
&& !is_numeric($_GET['pto'] ?? null)
)
{
$error = true;
$messageStack->add_session('search', ERROR_AT_LEAST_ONE_INPUT);
} else {
$dfrom = '';
$dto = '';
$pfrom = $_GET['pfrom'] ?? '';
$pto = $_GET['pto'] ?? '';
$keywords = '';
if (isset($_GET['dfrom']) && ($_GET['dfrom'] !== DATE_FORMAT_STRING)) {
$dfrom = $_GET['dfrom'];
}
if (isset($_GET['dto']) && ($_GET['dto'] !== DATE_FORMAT_STRING)) {
$dto = $_GET['dto'];
}
if (isset($_GET['keywords'])) {
$keywords = Text::input($_GET['keywords']);
}
$price_check_error = false;
if (!Text::is_empty($pfrom) && !settype($pfrom, 'double')) {
$error = true;
$price_check_error = true;
$messageStack->add_session('search', ERROR_PRICE_FROM_MUST_BE_NUM);
}
if (!Text::is_empty($pto) && !settype($pto, 'double')) {
$error = true;
$price_check_error = true;
$messageStack->add_session('search', ERROR_PRICE_TO_MUST_BE_NUM);
}
if (!$price_check_error && is_float($pfrom) && is_float($pto) && ($pfrom >= $pto)) {
$error = true;
$messageStack->add_session('search', ERROR_PRICE_TO_LESS_THAN_PRICE_FROM);
}
if (!Text::is_empty($keywords) && !tep_parse_search_string($keywords, $search_keywords)) {
$error = true;
$messageStack->add_session('search', ERROR_INVALID_KEYWORDS);
}
}
if (empty($dfrom) && empty($dto) && empty($pfrom) && empty($pto) && empty($keywords)) {
$error = true;
$messageStack->add_session('search', ERROR_AT_LEAST_ONE_INPUT);
}
if ($error) {
tep_redirect(tep_href_link('advanced_search.php', tep_get_all_get_params(), 'NONSSL', true, false));
}
$select_str = "SELECT DISTINCT p.products_id, m.*, p.*, pd.*, p.products_quantity AS in_stock, IF(s.status, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) AS final_price, IF(s.status, 1, 0) AS is_special ";
if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (!Text::is_empty($pfrom) || !Text::is_empty($pto)) ) {
$select_str .= ", SUM(tr.tax_rate) AS tax_rate ";
}
$from_str = "FROM products p LEFT JOIN manufacturers m using(manufacturers_id) LEFT JOIN specials s ON p.products_id = s.products_id";
if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (!Text::is_empty($pfrom) || !Text::is_empty($pto)) ) {
if (isset($_SESSION['customer_id'])) {
$country_id = $customer->get_country_id();
$zone_id = $customer->get_zone_id();
} else {
$country_id = STORE_COUNTRY;
$zone_id = STORE_ZONE;
}
$from_str .= " LEFT JOIN tax_rates tr ON p.products_tax_class_id = tr.tax_class_id LEFT JOIN zones_to_geo_zones gz ON tr.tax_zone_id = gz.geo_zone_id AND (gz.zone_country_id IS NULL OR gz.zone_country_id = '0' OR gz.zone_country_id = " . (int)$country_id . ") AND (gz.zone_id IS NULL OR gz.zone_id = '0' OR gz.zone_id = " . (int)$zone_id . ")";
}
$from_str .= ", products_description pd, categories c, products_to_categories p2c";
$where_str = " WHERE p.products_status = 1 AND p.products_id = pd.products_id AND pd.language_id = " . (int)$languages_id . " AND p.products_id = p2c.products_id AND p2c.categories_id = c.categories_id ";
if (isset($_GET['categories_id']) && !Text::is_empty($_GET['categories_id'])) {
if (isset($_GET['inc_subcat']) && ($_GET['inc_subcat'] == '1')) {
$subcategories_array = [];
tep_get_subcategories($subcategories_array, $_GET['categories_id']);
$where_str .= " AND p2c.products_id = p.products_id AND p2c.products_id = pd.products_id AND (p2c.categories_id = " . (int)$_GET['categories_id'];
foreach ($subcategories_array as $subcategory_id) {
$where_str .= " OR p2c.categories_id = " . (int)$subcategory_id;
}
$where_str .= ")";
} else {
$where_str .= " AND p2c.products_id = p.products_id AND p2c.products_id = pd.products_id AND pd.language_id = " . (int)$languages_id . " AND p2c.categories_id = " . (int)$_GET['categories_id'];
}
}
if (isset($_GET['manufacturers_id']) && !Text::is_empty($_GET['manufacturers_id'])) {
$where_str .= " AND m.manufacturers_id = " . (int)$_GET['manufacturers_id'];
}
if (isset($search_keywords) && (count($search_keywords) > 0)) {
$where_str .= " AND (";
foreach ($search_keywords as $search_keyword) {
switch ($search_keyword) {
case '(':
case ')':
case 'and':
case 'or':
$where_str .= " " . $search_keyword . " ";
break;
default:
$keyword = Text::input($search_keyword);
$where_str .= "(";
if ( (defined('MODULE_HEADER_TAGS_PRODUCT_META_KEYWORDS_STATUS')) && (MODULE_HEADER_TAGS_PRODUCT_META_KEYWORDS_STATUS == 'True') ) {
$where_str .= "pd.products_seo_keywords LIKE '%" . tep_db_input($keyword) . "%' OR ";
}
$where_str .= "pd.products_name LIKE '%" . tep_db_input($keyword) . "%' OR p.products_model LIKE '%" . tep_db_input($keyword) . "%' OR m.manufacturers_name LIKE '%" . tep_db_input($keyword) . "%'";
if (isset($_GET['search_in_description']) && ($_GET['search_in_description'] == '1')) $where_str .= " OR pd.products_description LIKE '%" . tep_db_input($keyword) . "%'";
$where_str .= ')';
break;
}
}
$where_str .= " )";
}
if (!Text::is_empty($pfrom)) {
if ($currencies->is_set($currency)) {
$rate = $currencies->get_value($currency);
$pfrom = $pfrom / $rate;
}
}
if (!Text::is_empty($pto)) {
if (isset($rate)) {
$pto = $pto / $rate;
}
}
if (DISPLAY_PRICE_WITH_TAX == 'true') {
if ($pfrom > 0) $where_str .= " AND (IF(s.status, s.specials_new_products_price, p.products_price) * IF(gz.geo_zone_id IS NULL, 1, 1 + (tr.tax_rate / 100) ) >= " . (double)$pfrom . ")";
if ($pto > 0) $where_str .= " AND (IF(s.status, s.specials_new_products_price, p.products_price) * IF(gz.geo_zone_id IS NULL, 1, 1 + (tr.tax_rate / 100) ) <= " . (double)$pto . ")";
} else {
if ($pfrom > 0) $where_str .= " AND (IF(s.status, s.specials_new_products_price, p.products_price) >= " . (double)$pfrom . ")";
if ($pto > 0) $where_str .= " AND (IF(s.status, s.specials_new_products_price, p.products_price) <= " . (double)$pto . ")";
}
if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (!Text::is_empty($pfrom) || !Text::is_empty($pto)) ) {
$where_str .= " GROUP BY p.products_id, tr.tax_priority";
}
$listing_sql = $select_str . $from_str . $where_str;
require $oscTemplate->map_to_template(__FILE__, 'page');
require 'includes/application_bottom.php';