keywords2categories / api / autocomplete / autocomplete.php @ 2
Historie | Anzeigen | Annotieren | Download (4,59 KB)
1 | 1 | root | <?php
|
---|---|---|---|
2 | /* -----------------------------------------------------------------------------------------
|
||
3 | $Id: autocomplete.php 13450 2021-03-05 16:29:46Z GTB $
|
||
4 | |||
5 | modified eCommerce Shopsoftware
|
||
6 | http://www.modified-shop.org
|
||
7 | |||
8 | Copyright (c) 2009 - 2013 [www.modified-shop.org]
|
||
9 | -----------------------------------------------------------------------------------------
|
||
10 | Released under the GNU General Public License
|
||
11 | ---------------------------------------------------------------------------------------*/
|
||
12 | |||
13 | chdir('../../'); |
||
14 | include('includes/application_top.php'); |
||
15 | |||
16 | |||
17 | // include needed functions
|
||
18 | require_once (DIR_FS_INC.'xtc_parse_search_string.inc.php'); |
||
19 | |||
20 | $module_smarty = new Smarty; |
||
21 | $module_smarty->assign('language', $_SESSION['language']); |
||
22 | |||
23 | if (isset($_POST['queryString'])) { |
||
24 | |||
25 | $from_str = $where_str = ''; |
||
26 | |||
27 | $queryString = stripslashes(trim(decode_utf8(urldecode($_POST['queryString'])))); |
||
28 | $categories_id = !empty($_POST['categories_id']) ? (int)$_POST['categories_id'] : false; |
||
29 | $inc_subcat = !empty($_POST['inc_subcat']) ? (int)$_POST['inc_subcat'] : null; |
||
30 | |||
31 | // create $search_keywords array
|
||
32 | $keywordcheck = xtc_parse_search_string($queryString, $search_keywords); |
||
33 | |||
34 | if ($keywordcheck === true && mb_strlen($queryString, $_SESSION['language_charset']) >= SEARCH_AC_MIN_LENGTH) { |
||
35 | |||
36 | $from_str .= SEARCH_IN_ATTR == 'true' ? " LEFT OUTER JOIN ".TABLE_PRODUCTS_ATTRIBUTES." AS pa ON (p.products_id = pa.products_id) |
||
37 | LEFT OUTER JOIN ".TABLE_PRODUCTS_OPTIONS_VALUES." AS pov ON (pa.options_values_id = pov.products_options_values_id) " : ""; |
||
38 | $from_str .= SEARCH_IN_MANU == 'true' ? " LEFT OUTER JOIN ".TABLE_MANUFACTURERS." AS m ON (p.manufacturers_id = m.manufacturers_id) " : ""; |
||
39 | |||
40 | if (SEARCH_IN_FILTER == 'true') { |
||
41 | $from_str .= "LEFT JOIN ".TABLE_PRODUCTS_TAGS." pt ON (pt.products_id = p.products_id) |
||
42 | LEFT JOIN ".TABLE_PRODUCTS_TAGS_VALUES." ptv ON (ptv.options_id = pt.options_id AND ptv.values_id = pt.values_id AND ptv.status = '1' AND ptv.languages_id = '".(int)$_SESSION['languages_id']."') "; |
||
43 | } |
||
44 | |||
45 | //include subcategories if needed
|
||
46 | if ($categories_id !== false) { |
||
47 | if ($inc_subcat == '1') { |
||
48 | $subcategories_array = array(); |
||
49 | xtc_get_subcategories($subcategories_array, $categories_id); |
||
50 | $from_str .= " LEFT OUTER JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." AS p2c ON (p.products_id = p2c.products_id) "; |
||
51 | $where_str .= " AND p2c.categories_id IN ('".$categories_id."' "; |
||
52 | foreach ($subcategories_array AS $scat) { |
||
53 | $where_str .= ", '".$scat."'"; |
||
54 | } |
||
55 | $where_str .= ") "; |
||
56 | } else {
|
||
57 | $from_str .= " LEFT OUTER JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." AS p2c ON (p.products_id = p2c.products_id) "; |
||
58 | $where_str .= " AND p2c.categories_id = '".$categories_id."' "; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | include(DIR_WS_INCLUDES.'build_search_query.php'); |
||
63 | |||
64 | $where_str .= " ) "; |
||
65 | |||
66 | $autocomplete_search_query = "SELECT ".$product->default_select." |
||
67 | FROM ".TABLE_PRODUCTS." p |
||
68 | JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd |
||
69 | ON p.products_id = pd.products_id
|
||
70 | AND pd.language_id = '".(int)$_SESSION['languages_id']."' |
||
71 | AND trim(pd.products_name) != ''
|
||
72 | ".$from_str." |
||
73 | WHERE p.products_status = '1'
|
||
74 | ".$where_str." |
||
75 | ".PRODUCTS_CONDITIONS_P." |
||
76 | GROUP BY p.products_id
|
||
77 | ORDER BY p.products_id ASC
|
||
78 | LIMIT ".MAX_DISPLAY_ADVANCED_SEARCH_RESULTS; |
||
79 | |||
80 | $autocomplete_search_query = xtc_db_query($autocomplete_search_query); |
||
81 | if (xtc_db_num_rows($autocomplete_search_query) > 0) { |
||
82 | $module_content = array(); |
||
83 | while ($autocomplete_search = xtc_db_fetch_array($autocomplete_search_query)) { |
||
84 | $module_content[] = $product->buildDataArray($autocomplete_search); |
||
85 | } |
||
86 | $module_smarty->assign('module_content', $module_content); |
||
87 | } else {
|
||
88 | $module_smarty->assign('error', 'true'); |
||
89 | } |
||
90 | $module_smarty->caching = 0; |
||
91 | $module_smarty->display(CURRENT_TEMPLATE.'/module/autocomplete.html'); |
||
92 | } |
||
93 | } |
||
94 | ?> |