$keyword_arr[$k] = strtr($keyword, $sql_words_array); } } $query_name = $query_model = $queryArticle = $queryProducts = $queryProductsDefault = []; foreach ($keyword_arr as $k) { $query_name[] = 'LOWER(pd.products_name) LIKE "%' . mb_strtolower($k) . '%"'; $query_model[] = 'LOWER(p.products_model) LIKE "%' . mb_strtolower($k) . '%"'; $queryArticle[] = 'LOWER(pa_article) LIKE "%' . mb_strtolower($k) . '%"'; $queryProductsDefault[] = 'LOWER(p.products_id) LIKE "%' . mb_strtolower($k) . '%"'; } $queryArticle = implode(' AND ', $queryArticle); $queryArticle = tep_db_query("SELECT products_id FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE " . $queryArticle); while ($row = tep_db_fetch_array($queryArticle)) { $queryProducts[] = 'LOWER(p.products_id) LIKE "%' . mb_strtolower($row['products_id']) . '%"'; } $query_name = implode(' AND ', $query_name); $query_model = implode(' AND ', $query_model); $queryProducts = $queryProducts ?: $queryProductsDefault; $queryProducts = implode(' AND ', $queryProducts); $where_keywords .= " (($query_name) or ($query_model) or ($queryProducts)) and"; // subcategories for search results: if (!empty($_GET['cid'])) { $clear_pid = (int)tep_db_input($_GET['cid']); if ($cat_list[$clear_pid]) { $all_search_cats = implode(',', $cat_list[$clear_pid]); } else { $all_search_cats = $clear_pid; } $where_subcategories = " p2c.categories_id in(" . $all_search_cats . ") and"; } $search_enhancements_keywords = addslashes(strip_tags(tep_db_input($_GET['keywords']))); if ($search_enhancements_keywords != $last_search_insert) { tep_db_query("insert into search_queries (search_text) values ('" . $search_enhancements_keywords . "')"); tep_session_register('last_search_insert'); $last_search_insert = $search_enhancements_keywords; } // $m_srch_action = 'keywords='.$_GET['keywords']; $m_srch_action = 'index.php'; } } if (DISPLAY_PRICE_WITH_TAX == 'true') { $type_join .= "LEFT JOIN " . TABLE_TAX_RATES . " tr on p.products_tax_class_id = tr.tax_class_id"; if (isset($_GET['rmin']) || isset($_GET['rmax'])) { $type_join .= " LEFT JOIN " . TABLE_ZONES_TO_GEO_ZONES . " za ON tr.tax_zone_id = za.geo_zone_id"; } } // show products from current category or from search $listing_sql = "select distinct p.products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p " . $type_join . " " . $filter_join . " where " . $where_filters . " " . $where_keywords . " " . $where_manufacturers . " " . $where_type . " " . $where_subcategories . " p.products_status = 1 and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "'"; switch ($_GET['sort']) { case 'name': if ((isset($current_category['display_products']) && $current_category['display_products'] === 'products_ordered') && !isset($_GET['sort'])) { $listing_sql .= " order by p.products_quantity > 0 desc, p.products_ordered desc"; } else { $listing_sql .= " order by p.products_quantity > 0 desc, p.products_sort_order, pd.products_name"; } break; case 'price_ub': $listing_sql .= " order by p.products_quantity > 0 desc, $customer_price desc"; break; case 'price_vozr': $listing_sql .= " order by p.products_quantity > 0 desc, $customer_price"; break; case 'new': $listing_sql .= " order by p.products_quantity > 0 desc, p.products_date_added desc"; break; case 'viewed': default: $listing_sql .= " order by p.products_quantity > 0 desc, pd.products_viewed desc"; break; } $listing_sql_raw = $listing_sql; // split query to 2 small queries: 1) find all products ids, 2) get info for each product $pids_price_filter_excluded = tep_get_all_pids_price_exclude($listing_sql, $price_filter_statement); $pids_filter_excluded = tep_get_all_pids_price_exclude($listing_sql, str_replace($price_filter_statement, '', $where_filters)); $pids_filter_excluded = $pids_filter_excluded ?: [0]; $where_attr = str_replace($manFilter, '', $where_filters); $pids_filter_attr_axcluded = tep_get_all_pids_price_exclude($listing_sql, str_replace($price_filter_statement, '', $where_attr)); $pids_filter_attr_axcluded = $pids_filter_attr_axcluded ?: []; $listing_sql = tep_get_query_products_info($listing_sql); // define how much products to show on page if (!empty($_GET['row_by_page'])) { if ($_GET['row_by_page'] == 'all') { $row_by_page = 1000; } elseif ((int)$_GET['row_by_page'] != 0) { $row_by_page = abs((int)$_GET['row_by_page']); } else { $row_by_page = explode(';', $template->getMainconf('MAX_DISPLAY_SEARCH_RESULTS_TITLE'))[0]; } } else { $row_by_page = explode(';', $template->getMainconf('MAX_DISPLAY_SEARCH_RESULTS_TITLE'))[0]; } if (is_array($all_pids)) { $all_pids_string = " p.products_id in(" . implode(',', $all_pids) . ") "; $number_of_rows = count($all_pids); } else { $all_pids_string = ''; $number_of_rows = 0; } $listing_split = new splitPageResults($listing_sql, $row_by_page ?: 10, 'p.products_id', 'page', $number_of_rows); $listing_query = tep_db_query($listing_split->sql_query); //salemaker: get salemaker prices only for products from current page (uses only one sql-query) $salemakers_array = get_salemakers($listing_query); mysqli_data_seek($listing_query, 0); //$milliseconds = round(microtime(true) * 1000); //debug(round(microtime(true) * 1000) - $milliseconds); // PDF view: if ($_GET['pdf'] == 'true') { if (file_exists("ext/pdf_export/pdf.php")) { require_once "ext/pdf_export/pdf.php"; } } // END PDF view $row_bypage_array = array(); $display_results_array = explode( ';', ($template->getMainconf('MAX_DISPLAY_SEARCH_RESULTS_TITLE') . ';' . FILTER_ALL) ); foreach ($display_results_array as $k => $res) { $row_bypage_array[] = array('id' => (($res != FILTER_ALL) ? $res : 'all'), 'text' => $res); } $r_sort_array = array( array('id' => 'viewed', 'text' => LISTING_SORT_POPULAR), array('id' => 'name', 'text' => LISTING_SORT_NAME), array('id' => 'price_vozr', 'text' => LISTING_SORT_PRICE1), array('id' => 'price_ub', 'text' => LISTING_SORT_PRICE2), array('id' => 'new', 'text' => LISTING_SORT_NEW), ); $r_display_array = array( array('id' => 'list', 'text' => LISTING_SORT_LIST), array('id' => 'columns', 'text' => LISTING_SORT_COLUMNS) ); if ($_GET['display'] == '') { $display = $template->getMainconf('LIST_DISPLAY_TYPE') == 0 ? 'list' : 'columns'; } else { $display = $_GET['display']; } if ($display == 'list') { $display_hover_list = 'hover'; } elseif ($display == 'columns') { $display_hover_columns = 'hover'; } // ajax-form, where we adding hidden values of current selected attributes: foreach ($_GET as $k => $v) { if(!is_int($k)){ $k = preg_replace('/[^A-Za-z0-9_]/ui','',$k); } $v = preg_replace('/[?!^0-9-+()₴!\"№;%:?*_=\'~@#$^&\[\]\.\,><]/','',$v); if ($k == 'cPath' or $k == 'f' or $k == 'language' or $k == 'manufacturers_id') { } elseif (is_int($k)) { $m_srch .= ''; } else { if (isset($cPath) && $cPath == 0 && ($k == 'sort' || $k == 'type')) { if ($_GET['sort'] == 'new') { $heading_text_box = $zero_category_title = BOX_HEADING_WHATS_NEW; } if ($_GET['type'] == 'specials') { $heading_text_box = sprintf( BOX_HEADING_DEFAULT_SPECIALS, tep_date_long_translate(strftime('%B')) ); $zero_category_title = sprintf(BOX_HEADING_DEFAULT_SPECIALS, ''); } if ($_GET['sort'] == 'featured') { $heading_text_box = $zero_category_title = BOX_HEADING_FEATURED; } } else { $m_srch .= ''; } } } $m_srch = '
' . $m_srch . '
'; // END ajax-form; if (!empty($_GET['page']) && empty($redirectOptionsIdsArrayForCheck)) { $heading_text_box .= ($heading_text_box ? ' - ' : '') . PREVNEXT_TITLE_PPAGE . ' ' . $_GET['page']; } // Clear $desc_text seo filter if (!empty($_GET['filter_id'])) { $desc_text = ""; } } } else { // default page $content = CONTENT_INDEX_DEFAULT; $breadcrumb->add(TITLE); } //$milliseconds = round(microtime(true) * 1000); // attributes arrays: // get all attributes list from current category $counts_array = array(); $counts_may_be = array(); // array with all selected attributes $show_in_filter = array(); $attr_names_array = array(); $attr_sort_orders = array(); $show_in_product_listing = array(); $show_options_arr = []; if($content != CONTENT_INDEX_DEFAULT || !@file_get_contents(DIR_FS_CATALOG.'temp/attributes_'.$languages_id.'.json')){ getArrayWithAllAttributes(); } $options_string = generateOptionsString($attr_names_array, $attr_vals_names_array); if (!empty($options_string)) { $heading_text_box .= $options_string; } // --------------- ATTRIBUTES COUNTER IN FILTER ----------------------------- // if (defined('SEO_FILTER') && constant('SEO_FILTER') == 'true') { require(DIR_WS_MODULES . '/attributes_counter.php'); } // --------------- ATTRIBUTES COUNTER IN FILTER --END------------------------ // // END get list of all attributes from current category if ($_SESSION['view_order_success']) { unset($_SESSION['view_order_success']); } if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { require(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING_COL); } else { require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE); } require(DIR_WS_INCLUDES . 'application_bottom.php');