Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Improved Search Function

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #121  
Old 05-18-2005, 07:53 PM
 
IndieDepot IndieDepot is offline
 

Advanced Member
  
Join Date: May 2005
Posts: 30
 

Default

Quote:
Originally Posted by cherie
This is great. The x-cart search really needs to be improved. Can someone post the final version of the include/search.php they are using for 4.0.13?

Here Here.. I would also like a Final tally of what we need to do for 4.0.13. Code here code there code everywhere...i don't know what to grab. *smile*

One single final post with a 4.0.13 solution would be nice. *smile*

- Shannon
__________________
- www.TheShotList.com
X-Cart version 4.0.13
PHP 4.3.10
MySQL 4.0.23
Web server Apache
Operation system Linux
Perl 5.008004
XML parser (expat) 1.95.6
Reply With Quote
  #122  
Old 05-19-2005, 12:57 AM
 
html_sucks html_sucks is offline
 

Advanced Member
  
Join Date: May 2004
Location: London, UK
Posts: 63
 

Default

Try this ...

Code:
<?php /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2004 Ruslan R. Fazliev <rrf@rrf.ru> | | All rights reserved. | +-----------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" | | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.x-cart.com/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. | | FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.| | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2004 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: search.php,v 1.38.2.34 2004/12/16 11:10:49 max Exp $ # if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); } $advanced_options = array("productcode", "productid", "provider", "price_max", "avail_max", "weight_max", "forsale", "flag_free_ship", "flag_ship_freight", "flag_global_disc", "flag_free_tax", "flag_min_amount", "flag_low_avail_limit", "flag_list_price", "flag_vat", "flag_gstpst", "manufacturers"); $sort_fields = array( "productcode" => func_get_langvar_by_name("lbl_sku"), "title" => func_get_langvar_by_name("lbl_product"), "price" => func_get_langvar_by_name("lbl_price"), "orderby" => func_get_langvar_by_name("lbl_default") ); if($current_area == 'A' || $current_area == 'P') $sort_fields["quantity"] = func_get_langvar_by_name("lbl_quantity"); if ($REQUEST_METHOD == "POST") { # # Update the session $search_data variable from $posted_data # if (!empty($posted_data)) { $need_advanced_options = false; foreach ($posted_data as $k=>$v) { if (!is_array($v) && !is_numeric($v)) $posted_data[$k] = stripslashes($v); if (in_array($k, $advanced_options) and $v !== "") $need_advanced_options = true; } if (!$need_advanced_options) $need_advanced_options = (doubleval($posted_data["price_min"]) != 0 || intval($posted_data["avail_min"]) != 0 || doubleval($posted_data["weight_min"]) != 0); if (!$need_advanced_options and $current_area == "C" and !empty($posted_data["categoryid"])) $need_advanced_options = true; $posted_data["need_advanced_options"] = $need_advanced_options; # # Data convertation for Feature comparison module # if(!empty($active_modules['Feature_Comparison'])) { include $xcart_dir."/modules/Feature_Comparison/search_define.php"; } if (empty($search_data["products"]["sort_field"])) { $posted_data["sort_field"] = "title"; $posted_data["sort_direction"] = 0; } else { $posted_data["sort_field"] = $search_data["products"]["sort_field"]; $posted_data["sort_direction"] = $search_data["products"]["sort_direction"]; } $search_data["products"] = $posted_data; $search_data["is_modify"] = $is_modify; } func_header_location("search.php?mode=search"); } if ($mode == "search") { # # Perform search and display results # $data = array(); $flag_save = false; # # Prepare the search data # if (!empty($sort) and isset($sort_fields[$sort])) { # Store the sorting type in the session $search_data["products"]["sort_field"] = $sort; $flag_save = true; } if (isset($sort_direction)) { # Store the sorting direction in the session $search_data["products"]["sort_direction"] = $sort_direction; $flag_save = true; } if($current_area == 'C' && !empty($config['Appearance']['products_order']) && empty($search_data["products"]["sort_field"])) { $search_data["products"]["sort_field"] = $config['Appearance']['products_order']; $search_data["products"]["sort_direction"] = 0; } if (!empty($page) and $search_data["products"]["page"] != intval($page)) { # Store the current page number in the session $search_data["products"]["page"] = $page; $flag_save = true; } if (is_array($search_data["products"])) { $data = $search_data["products"]; foreach ($data as $k=>$v) if (!is_array($v) && !is_numeric($v)) $data[$k] = addslashes($v); } if(!isset($condition) || (isset($HTTP_GET_VARS['condition']) || isset($HTTP_POST_VARS['condition']) || isset($HTTP_COOKIE_VARS['condition']))) $condition = array(); if(!isset($join) || (isset($HTTP_GET_VARS['join']) || isset($HTTP_POST_VARS['join']) || isset($HTTP_COOKIE_VARS['join']))) $join = array(); if(!isset($add_fields) || (isset($HTTP_GET_VARS['add_fields']) || isset($HTTP_POST_VARS['add_fields']) || isset($HTTP_COOKIE_VARS['add_fields']))) $add_fields = array(); if(!isset($having) || (isset($HTTP_GET_VARS['having']) || isset($HTTP_POST_VARS['having']) || isset($HTTP_COOKIE_VARS['having']))) $having = array(); if(!isset($search_condition) || (isset($HTTP_GET_VARS['search_condition']) || isset($HTTP_POST_VARS['search_condition']) || isset($HTTP_COOKIE_VARS['search_condition']))) $search_condition = ""; $search_condition .= "$sql_tbl[pricing].productid=$sql_tbl[products].productid AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].membership IN ('".@$user_account['membership']."','')"; if($current_area == 'C' && !empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[pricing].variantid = 0 OR ($sql_tbl[variants].variantid = $sql_tbl[pricing].variantid".(($config["General"]["disable_outofstock_products"] == "Y" && $config["General"]["unlimited_products"] != "Y")?" AND $sql_tbl[variants].avail > 0":"")."))"; } else { $search_condition .= " AND $sql_tbl[pricing].variantid = 0"; } $data["substring"] = trim($data["substring"]); if (!empty($data["substring"])) { if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) { $search_data["products"]["by_title"] = $data["by_title"] = "Y"; $flag_save = true; } $ss = split(" ",$data["substring"]); $ss_condition = ""; foreach($ss as $s) { # Search for substring in some fields... $condition = array(); if (!empty($data["by_title"])) $condition[] = "$sql_tbl[products].product LIKE '%".$s."%'"; if (!empty($data["by_shortdescr"])) $condition[] = "$sql_tbl[products].descr LIKE '%".$s."%'"; if (!empty($data["by_fulldescr"])) $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$s."%'"; if (!empty($data["extra_fields"]) && $active_modules['Extra_Fields']) { foreach($data["extra_fields"] as $k => $v) $condition[] = "($sql_tbl[extra_field_values].value LIKE '%".$s."%' AND $sql_tbl[extra_fields].fieldid = '$k')"; $join['extra_field_values'] = "$sql_tbl[products].productid = $sql_tbl[extra_field_values].productid"; $join['extra_fields'] = "$sql_tbl[extra_field_values].fieldid = $sql_tbl[extra_fields].fieldid AND $sql_tbl[extra_fields].active = 'Y'"; } if (!empty($condition)) $ss_condition .= " AND (".implode(" OR ", $condition).")"; } $search_condition .= $ss_condition; # Search statistics db_query("INSERT INTO $sql_tbl[stats_search] (search, date) VALUES ('$data[substring]', '".time()."')"); } # /if (!empty($data["substring"])) # # Search by product features # if(!empty($active_modules['Feature_Comparison'])) { include $xcart_dir."/modules/Feature_Comparison/search_define.php"; } # # Internation names & descriptions # if($current_area == 'C' || $current_area == 'P') { $add_fields[] = "$sql_tbl[products_lng].product as product_lng"; $add_fields[] = "$sql_tbl[products_lng].descr as descr_lng"; $add_fields[] = "$sql_tbl[products_lng].full_descr as fulldescr_lng"; $join['products_lng'] = "$sql_tbl[products_lng].productid = $sql_tbl[products].productid AND $sql_tbl[products_lng].code = '$shop_language'"; } if(!empty($data["manufacturers"]) && $active_modules['Manufacturers']) { $search_condition .= " AND $sql_tbl[products].manufacturerid IN ('".implode("','", $data["manufacturers"])."')"; } $search_condition .= " AND $sql_tbl[products_categories].productid=$sql_tbl[products].productid AND $sql_tbl[products_categories].categoryid = $sql_tbl[categories].categoryid"; if($current_area == 'C') { $search_condition .= " AND $sql_tbl[categories].membership IN ('','".addslashes(@$user_account['membership'])."')"; } $from_tbl[$sql_tbl["products_categories"]] = 1; $from_tbl[$sql_tbl["categories"]] = 1; if (!empty($data["categoryid"])) { # Search by category... $data["categoryid"] = intval($data["categoryid"]); $category_sign = ""; if (empty($data["category_main"]) && empty($data["category_extra"])) { $category_sign = "NOT"; } if (!empty($data["search_in_subcategories"])) { # Search also in all subcategories $categoryid_path = addslashes(func_query_first_cell("SELECT categoryid_path FROM $sql_tbl[categories] WHERE categoryid='".$data["categoryid"]."'")); $categoryids_tmp = func_query("SELECT categoryid FROM $sql_tbl[categories] WHERE categoryid='".$data["categoryid"]."' OR categoryid_path LIKE '$categoryid_path/%'"); if (is_array($categoryids_tmp) && !empty($categoryids_tmp)) { foreach ($categoryids_tmp as $k=>$v) { $categoryids[] = $v["categoryid"]; } $search_condition .= " AND $sql_tbl[products_categories].categoryid $category_sign IN (".implode(",", $categoryids).")"; } } else { $search_condition .= " AND $category_sign $sql_tbl[products_categories].categoryid='$data[categoryid]'"; } $condition = array(); if (!empty($data["category_main"])) $condition[] = "$sql_tbl[products_categories].main='Y'"; if (!empty($data["category_extra"])) $condition[] = "$sql_tbl[products_categories].main!='Y'"; if (!empty($condition)) $search_condition .= " AND (".implode(" OR ", $condition).")"; } elseif($current_area == 'C') { } # /if (!empty($data["categoryid"])) if (!empty($data["productcode"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].productcode LIKE '%".$data["productcode"]."%' OR $sql_tbl[variants].productcode LIKE '%".$data["productcode"]."%')"; } else { $search_condition .= " AND $sql_tbl[products].productcode LIKE '%".$data["productcode"]."%'"; } } if (!empty($data["productid"])) $search_condition .= " AND $sql_tbl[products].productid='".$data["productid"]."'"; if (!empty($data["provider"])) $search_condition .= " AND $sql_tbl[products].provider LIKE '%".$data["provider"]."%'"; if (!empty($data["price_min"])) { if(!empty($active_modules['Product_Options'])) { $having[] = "(price>='".$data["price_min"]."' OR v_price>='".$data["price_min"]."')"; # $search_condition .= " AND ($sql_tbl[pricing].price>='".$data["price_min"]."' OR v_pricing.price>='".$data["price_min"]."')"; } else { $search_condition .= " AND $sql_tbl[pricing].price>='".$data["price_min"]."'"; } } if (strlen(@$data["price_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $having[] = "(price<='".$data["price_max"]."' OR v_price<='".$data["price_max"]."')"; # $search_condition .= " AND ($sql_tbl[pricing].price<='".$data["price_max"]."' OR v_pricing.price<='".$data["price_max"]."')"; } else { $search_condition .= " AND $sql_tbl[pricing].price<='".$data["price_max"]."'"; } } if (!empty($data["avail_min"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].avail>='".$data["avail_min"]."' OR $sql_tbl[variants].avail>='".$data["avail_min"]."')"; } else { $search_condition .= " AND $sql_tbl[products].avail>='".$data["avail_min"]."'"; } } if (strlen(@$data["avail_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].avail<='".$data["avail_max"]."' OR $sql_tbl[variants].avail<='".$data["avail_max"]."')"; } else { $search_condition .= " AND $sql_tbl[products].avail<='".$data["avail_max"]."'"; } } if (!empty($data["weight_min"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].weight>='".$data["weight_min"]."' OR $sql_tbl[variants].weight>='".$data["weight_min"]."')"; } else { $search_condition .= " AND $sql_tbl[products].weight>='".$data["weight_min"]."'"; } } if (strlen(@$data["weight_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].weight<='".$data["weight_max"]."' OR $sql_tbl[variants].weight<='".$data["weight_max"]."')"; } else { $search_condition .= " AND $sql_tbl[products].weight<='".$data["weight_max"]."'"; } } if (!empty($data["forsale"])) $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."'"; if (!empty($data["flag_free_ship"])) $search_condition .= " AND $sql_tbl[products].free_shipping='".$data["flag_free_ship"]."'"; if (!empty($data["flag_ship_freight"])) $search_condition .= " AND $sql_tbl[products].shipping_freight='".$data["flag_ship_freight"]."'"; if (!empty($data["flag_ship_freight"])) { if ($data["flag_ship_freight"] == "Y") $search_condition .= " AND $sql_tbl[products].shipping_freight>'0'"; else $search_condition .= " AND $sql_tbl[products].shipping_freight='0'"; } if (!empty($data["flag_global_disc"])) $search_condition .= " AND $sql_tbl[products].discount_avail='".$data["flag_global_disc"]."'"; if (!empty($data["flag_free_tax"])) $search_condition .= " AND $sql_tbl[products].free_tax='".$data["flag_free_tax"]."'"; if (!empty($data["flag_min_amount"])) { if ($data["flag_min_amount"] == "Y") $search_condition .= " AND $sql_tbl[products].min_amount!='1'"; else $search_condition .= " AND $sql_tbl[products].min_amount='1'"; } if (!empty($data["flag_low_avail_limit"])) { if ($data["flag_low_avail_limit"] == "Y") $search_condition .= " AND $sql_tbl[products].low_avail_limit!='10'"; else $search_condition .= " AND $sql_tbl[products].low_avail_limit='10'"; } if (!empty($data["flag_list_price"])) { if ($data["flag_list_price"] == "Y") $search_condition .= " AND $sql_tbl[products].list_price!='0'"; else $search_condition .= " AND $sql_tbl[products].list_price='0'"; } if (!empty($data["flag_vat"])) { if ($data["flag_vat"] == "Y") $search_condition .= " AND $sql_tbl[products].vat!='0'"; else $search_condition .= " AND $sql_tbl[products].vat='0'"; } if (!empty($data["flag_gstpst"])) { if ($data["flag_gstpst"] == "Y") $search_condition .= " AND ($sql_tbl[products].apply_gst='Y' OR $sql_tbl[products].apply_pst='Y')"; else $search_condition .= " AND $sql_tbl[products].apply_gst='N' AND $sql_tbl[products].apply_pst='N'"; } if(!empty($active_modules['Product_Options'])) { $join['classes'] = "$sql_tbl[classes].productid = $sql_tbl[products].productid"; $join["variants"] = "$sql_tbl[variants].productid = $sql_tbl[products].productid"; $join["pricing v_pricing"] = "v_pricing.variantid = $sql_tbl[variants].variantid AND v_pricing.quantity = 1 AND v_pricing.membership IN ('','".@$user_account['membership']."')"; $add_fields[] = "IF($sql_tbl[variants].variantid IS NOT NULL,'Y','') as is_variant"; $add_fields[] = "IF($sql_tbl[classes].classid IS NOT NULL,'Y','') as is_product_options"; $add_fields[] = "v_pricing.price as v_price"; } if (!empty($data["sort_field"])) { # Sort the search results... $direction = ($data["sort_direction"] ? "DESC" : "ASC"); switch ($data["sort_field"]) { case "productcode": $sort_string = "$sql_tbl[products].productcode $direction"; break; case "title": $sort_string = "$sql_tbl[products].product $direction"; break; case "orderby": $sort_string = "$sql_tbl[products_categories].orderby $direction"; break; case "quantity": $sort_string = "$sql_tbl[products].avail $direction"; break; case "price": if (!empty($active_modules["Special_Offers"]) && !empty($search_data["products"]["show_special_prices"])) { $sort_string = "x_special_price $direction, price $direction"; } else { $sort_string = "price $direction"; } break; default: $sort_string = "$sql_tbl[products].product"; } } else { $sort_string = "$sql_tbl[products].product"; } if(!empty($data['sort_condition'])) { $sort_string = $data['sort_condition']; } if ($config["General"]["unlimited_products"]=="N" && ($current_area == "C" || $current_area == "B") && $config["General"]["disable_outofstock_products"] == "Y") { $search_condition .= " AND ($sql_tbl[products].avail>0 OR $sql_tbl[products].product_type NOT IN ('','N')) "; } if (!empty($from_tbl) and is_array($from_tbl)) $from_tbl = ", ".implode(", ", array_keys($from_tbl)); # # Generate LEFT JOIN string # $join_string = ''; if(!empty($join) && @is_array($join)) { foreach($join as $k => $v) { list($name, $as) = explode(" ", $k); if(!empty($as)) $as = " as ".$as; $join_string .= " LEFT JOIN ".$sql_tbl[$name].$as." ON $v "; } } # # Generate HAVING string # $having_string = ''; if(!empty($having)) { $having_string = " HAVING ".implode(" AND ", $having); } # # Generate additional fields string # $add_fields_string = ''; if(!empty($add_fields) && @is_array($add_fields)) { $add_fields_string = ", ".implode(", ", $add_fields); } # # Calculate the number of rows in the search results # $_res = db_query("SELECT COUNT($sql_tbl[products].productid), MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string"); $total_items = db_num_rows($_res); db_free_result($_res); if ($total_items > 0) { $page = $search_data["products"]["page"]; # # Prepare the page navigation # if(!isset($objects_per_page)) { if ($current_area == "C" || $current_area == "B") $objects_per_page = $config["Appearance"]["products_per_page"]; else $objects_per_page = $config["Appearance"]["products_per_page_admin"]; } $total_nav_pages = ceil($total_items/$objects_per_page)+1; include $xcart_dir."/include/navigation.php"; # # Perform the SQL query and getting the search results # if (!empty($search_data["is_modify"])) { # # Get the products and go to modify them # $products = func_query("SELECT $sql_tbl[products].productid, MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string"); if (is_array($products)) { x_session_register("store_productids"); $store_productids = array(); foreach($products as $v) $store_productids[$v['productid']] = true; func_header_location("product_modify.php?mode=return"); } } else $products = func_query("SELECT $sql_tbl[products].*, MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string ORDER BY $sort_string, $sql_tbl[products].product ASC LIMIT $first_page, $objects_per_page"); if (!empty($products)) { foreach ($products as $k=>$v) { $products[$k]['taxed_price'] = $v['price']; } } if (!empty($products) and $current_area == "C") { x_session_register("cart"); foreach ($products as $k=>$v) { if(!empty($active_modules['Feature_Comparison'])) { $products[$k]['is_clist'] = func_check_comparison($v['productid']); } $in_cart = 0; if(!empty($cart['products'])) { foreach($cart['products'] as $cv) { if($cv['productid'] == $v['productid']) $in_cart += $cv['amount']; } $products[$k]['avail'] -= $in_cart; if($products[$k]['avail'] < 0) { $products[$k]['avail'] = 0; } } $products[$k]["tmbn_url"] = func_get_thumbnail_url($v["productid"]); if(!empty($v['product_lng'])) $products[$k]['product'] = $v['product_lng']; if(!empty($v['descr_lng'])) $products[$k]['descr'] = $v['descr_lng']; if(!empty($v['fulldescr_lng'])) $products[$k]['fulldescr'] = $v['fulldescr_lng']; unset($products[$k]['product_lng'], $products[$k]['descr_lng'], $products[$k]['fulldescr_lng']); if (!empty($active_modules["Special_Offers"]) && !empty($search_data["products"]["show_special_prices"])) { include $xcart_dir."/modules/Special_Offers/search_results_calculate.php"; } else { $products[$k]["taxes"] = func_get_product_taxes($products[$k], $login); } if($products[$k]['descr'] == strip_tags($products[$k]['descr'])) $products[$k]['descr'] = str_replace("\n"," ",$products[$k]['descr']); if($products[$k]['fulldescr'] == strip_tags($products[$k]['fulldescr'])) $products[$k]['fulldescr'] = str_replace("\n"," ",$products[$k]['fulldescr']); } if (!empty($active_modules["Special_Offers"]) && empty($search_data["products"]["show_special_prices"])) { func_offers_check_products($login, $current_area, $products); } } # Assign the Smarty variables $smarty->assign("navigation_script","search.php?mode=search"); $smarty->assign("products", $products); $smarty->assign("first_item", $first_page+1); $smarty->assign("last_item", min($first_page+$objects_per_page, $total_items)); } $smarty->assign("total_items",$total_items); $smarty->assign("mode", $mode); if ($flag_save) x_session_save("search_data"); } if (empty($search_data["products"]) && $current_area == 'C') { $search_data["products"]['productcode'] = $config['Search_products']['search_products_sku_d']; $search_data["products"]['price_min'] = preg_replace("/-.*$/", "", $config['Search_products']['search_products_price_d']); $search_data["products"]['price_max'] = preg_replace("/^.*-/", "", $config['Search_products']['search_products_price_d']); $search_data["products"]['weight_min'] = preg_replace("/-.*$/", "", $config['Search_products']['search_products_weight_d']); $search_data["products"]['weight_max'] = preg_replace("/^.*-/", "", $config['Search_products']['search_products_weight_d']); $search_data["products"]['categoryid'] = $config['Search_products']['search_products_category_d']; } if (!empty($active_modules['Feature_Comparison']) && $current_area != 'C' && $current_area != 'P') { $fclasses = func_query("SELECT $sql_tbl[feature_classes].*, IF($sql_tbl[feature_classes_lng].class IS NOT NULL, $sql_tbl[feature_classes_lng].class, $sql_tbl[feature_classes].class) as class FROM $sql_tbl[feature_classes] LEFT JOIN $sql_tbl[feature_classes_lng] ON $sql_tbl[feature_classes].fclassid = $sql_tbl[feature_classes_lng].fclassid AND $sql_tbl[feature_classes_lng].code = '$shop_language' WHERE $sql_tbl[feature_classes].avail = 'Y' ORDER BY $sql_tbl[feature_classes].orderby"); if(!empty($fclasses)) { $smarty->assign("fclasses", $fclasses); } } $smarty->assign("search_prefilled", $search_data["products"]); if($active_modules['Manufacturers']) { $manufacturers = func_query("SELECT * FROM $sql_tbl[manufacturers] WHERE avail = 'Y' ORDER BY orderby,manufacturer"); if($manufacturers) { array_unshift($manufacturers, array("manufacturerid" => '0', "manufacturer" => func_get_langvar_by_name("lbl_no_manufacturer"))); $tmp = explode("\n", $config['Search_products']['search_products_manufacturers_d']); foreach($manufacturers as $k => $v) { if(@in_array($v['manufacturerid'], (array)$search_data["products"]['manufacturers']) || (in_array($v['manufacturerid'], $tmp) && $current_area == 'C')) $manufacturers[$k]['selected'] = 'Y'; } if($manufacturers) $smarty->assign("manufacturers", $manufacturers); } } if($active_modules['Extra_Fields']) { $extra_fields = func_query("SELECT * FROM $sql_tbl[extra_fields] WHERE active = 'Y' ORDER BY field"); if($extra_fields) { $tmp = explode("\n", $config['Search_products']['search_products_extra_fields']); foreach($extra_fields as $k => $v) { if(!in_array($v['fieldid'], $tmp) && $current_area == 'C') { unset($extra_fields[$k]); continue; } if($search_data["products"]['extra_fields'][$v['fieldid']]) $extra_fields[$k]['selected'] = 'Y'; } if($extra_fields) $smarty->assign("extra_fields", $extra_fields); } } if($current_area != 'C') include $xcart_dir."/include/categories.php"; $search_categories = $smarty->get_template_vars("allcategories"); $smarty->assign("search_categories", $search_categories); if(!defined('IS_ROBOT')) $smarty->assign("sort_fields", $sort_fields); $smarty->assign("main","search"); ?>
__________________
X-Cart v4.2.0, v4.0.13, v4.0.9, v4.0.17
Reply With Quote
  #123  
Old 05-19-2005, 01:44 PM
 
IndieDepot IndieDepot is offline
 

Advanced Member
  
Join Date: May 2005
Posts: 30
 

Default

Thanks,

WOrks like a charm in a fresh 4.0.13 install. *smile*

- Shannon
__________________
- www.TheShotList.com
X-Cart version 4.0.13
PHP 4.3.10
MySQL 4.0.23
Web server Apache
Operation system Linux
Perl 5.008004
XML parser (expat) 1.95.6
Reply With Quote
  #124  
Old 05-19-2005, 02:37 PM
 
heartsfire heartsfire is offline
 

Member
  
Join Date: Oct 2004
Location: Las Vegas, NV
Posts: 13
 

Default No Clue

Using 4.0.12. Whenever I have tried to use this mod the same thing has happened. As soon as I hit search it takes me back to the index page (home page). When I use the default search.php it searches without problem.

I know less about JS than I do PHP. SO I have no clue where to even start looking at this.
__________________
Ron Eason
http://www.heartsfireleathers.com
webmaster@heartsfireleathers.com
XCART 4.0.12
Reply With Quote
  #125  
Old 05-19-2005, 03:09 PM
  chetlucas's Avatar 
chetlucas chetlucas is offline
 

Advanced Member
  
Join Date: Oct 2003
Location: Inverness, Florida
Posts: 56
 

Default Parse error when stripping the "s" from include/se

I have added the below code to remove the last "s" from search string, but receive a smarty sparse error "Parse error: parse error, unexpected $ in /home/giftcom/public_html/include/search.php on line 659"

// LOOK HERE
// new bit to split search string into separate words
$con = ""; $substr = "";
$and="AND";

if(!$substring) { $substring=" "; }
if(!empty($substring)){

// code to strip last s from search string
$substring = trim($substring);
$start = (strlen($substring)-1);
// echo $start;
// echo "
";
if ((substr($substring,$start,1)=="s")||(substr($subs tring,$start,1)=="S")){
$substring = substr($substring,0,$start);
// echo $substring;
}
// end of new funkydunk bit

Can this be fixed? What and where does the correct code go?
__________________
X-Cart version 4.1.11 (Unix)
Apache version 1.3.41 (Unix)
MySQL version 5.0.67 - community
PHP version 5.2.5
PERL version 5.8.8
http://www.etekmart.com
Reply With Quote
  #126  
Old 05-19-2005, 03:55 PM
  CenturyPerf's Avatar 
CenturyPerf CenturyPerf is offline
 

eXpert
  
Join Date: Jun 2003
Location: Reno, Nevada
Posts: 396
 

Default

It does not like me .... just blows up the page. I MUST be doing something wrong.

All I did was copy and paste the entire code in place of that in search.php
__________________
Best Regards,

Sam Solace - Pres/CEO
Century Performance Center, Inc.
http://www.centuryperformance.com

(3) sites using X-Cart 5.3.5.5
X-Payments Enterprise 3.1.4
Reply With Quote
  #127  
Old 05-20-2005, 05:58 AM
 
Sonia Sonia is offline
 

Advanced Member
  
Join Date: Feb 2005
Posts: 72
 

Default

Quote:
All I did was copy and paste the entire code in place of that in search.php

Did you try putting that new search.php file into the "include" folder? I just did that and it worked like a charm.
__________________
Sonia

www.vidaville.com
Xcart Gold 4.0.16
platform - Windows
Reply With Quote
  #128  
Old 05-22-2005, 04:09 PM
 
mikebo mikebo is offline
 

Advanced Member
  
Join Date: Feb 2004
Location: Ohio
Posts: 72
 

Default

To get the search to pick up product codes (sku's) in my 4.0.13 store where I do not use the full description field, I did a search and replace with my text editor in the following files:

search.php
include/search.php
skin1/customer/search.tpl

I replaced "fulldescr" with "productcode". This seems to work great for picking up the product code.

To get the s's stripped from the search term, I revised funkydunk's original code a bit.

In the 4.0.13 include/search.php file,

I replaced this

Code:
$data["substring"] = trim($data["substring"]);


with this

Code:
$data["substring"] = trim($data["substring"]); // code to strip last s from search string $start = (strlen($data["substring"])-1); // echo $start; // echo " "; if ((substr($data["substring"],$start,1)=="s")||(substr($data["substring"],$start,1)=="S")){ $data["substring"] = substr($data["substring"],0,$start); // echo $substring; } // end of code to strip last s from search string


This seems to work fine.

Hope this helps.
__________________
Mike
X-Cart Gold
Version 4.6.0 PHP 5.2.17
Reply With Quote
  #129  
Old 05-22-2005, 04:21 PM
  chetlucas's Avatar 
chetlucas chetlucas is offline
 

Advanced Member
  
Join Date: Oct 2003
Location: Inverness, Florida
Posts: 56
 

Default Improved Search Function - Fix

Thanks, this works great in 4.0.13 for stripping the 's' and making a search on plurals possible.
__________________
X-Cart version 4.1.11 (Unix)
Apache version 1.3.41 (Unix)
MySQL version 5.0.67 - community
PHP version 5.2.5
PERL version 5.8.8
http://www.etekmart.com
Reply With Quote
  #130  
Old 05-27-2005, 12:22 PM
 
Tuner Tuner is offline
 

eXpert
  
Join Date: Jan 2003
Location: Scottsdale Arizona
Posts: 245
 

Default

Hear is a compilation of everything I have found on this list for 4.0.13
*Bluecats Original Posted search.php (so I think)
+Categories Fixed
+Sku Mod (Note: You must add a hidden field or checkbox in /customer/main/search_results.tpl see below)
+Strip "S" Mod
+ Match Any Term Mod OR Match Exact Phrase (Uncomment/Comment starting at line 211)
+Allow Simple search on Home page to search sku, extra fields, title, descr and fulldescr(see below)

Notes:
(Works in 4.0.13)
This was the pinnacle of what I wanted, now all I need is it to sort by how many times the Query (keywords) matches a product So if the words ferrari and Enzo were found 5 times in One product and only 2 times in another it shows the product with the most instances of that keyword First.

The Match Any Term(default) is less picky and gives a broad search results. Unfortunately the results are not Sorted by relavance to the search phrase.(this is the only mainstream improvement I see left to develope.)
(7/15/05) Mach Any Term was default in this mod I am switching back to x-carts default of Match Phrase.


Scott

Hear is the Code(/include/search.php):
Code:
<?php /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2004 Ruslan R. Fazliev <rrf@rrf.ru> | | All rights reserved. | +-----------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" | | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.x-cart.com/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. | | FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.| | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2004 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: search.php,v 1.38.2.34 2004/12/16 11:10:49 max Exp $ # if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); } $advanced_options = array("productcode", "productid", "provider", "price_max", "avail_max", "weight_max", "forsale", "flag_free_ship", "flag_ship_freight", "flag_global_disc", "flag_free_tax", "flag_min_amount", "flag_low_avail_limit", "flag_list_price", "flag_vat", "flag_gstpst", "manufacturers"); $sort_fields = array( "productcode" => func_get_langvar_by_name("lbl_sku"), "title" => func_get_langvar_by_name("lbl_product"), "price" => func_get_langvar_by_name("lbl_price"), "orderby" => func_get_langvar_by_name("lbl_default") ); if($current_area == 'A' || $current_area == 'P') $sort_fields["quantity"] = func_get_langvar_by_name("lbl_quantity"); if ($REQUEST_METHOD == "POST") { # # Update the session $search_data variable from $posted_data # if (!empty($posted_data)) { $need_advanced_options = false; foreach ($posted_data as $k=>$v) { if (!is_array($v) && !is_numeric($v)) $posted_data[$k] = stripslashes($v); if (in_array($k, $advanced_options) and $v !== "") $need_advanced_options = true; } if (!$need_advanced_options) $need_advanced_options = (doubleval($posted_data["price_min"]) != 0 || intval($posted_data["avail_min"]) != 0 || doubleval($posted_data["weight_min"]) != 0); if (!$need_advanced_options and $current_area == "C" and !empty($posted_data["categoryid"])) $need_advanced_options = true; $posted_data["need_advanced_options"] = $need_advanced_options; # # Data convertation for Feature comparison module # if(!empty($active_modules['Feature_Comparison'])) { include $xcart_dir."/modules/Feature_Comparison/search_define.php"; } if (empty($search_data["products"]["sort_field"])) { $posted_data["sort_field"] = "title"; $posted_data["sort_direction"] = 0; } else { $posted_data["sort_field"] = $search_data["products"]["sort_field"]; $posted_data["sort_direction"] = $search_data["products"]["sort_direction"]; } $search_data["products"] = $posted_data; $search_data["is_modify"] = $is_modify; } func_header_location("search.php?mode=search"); } if ($mode == "search") { # # Perform search and display results # $data = array(); $flag_save = false; # # Prepare the search data # if (!empty($sort) and isset($sort_fields[$sort])) { # Store the sorting type in the session $search_data["products"]["sort_field"] = $sort; $flag_save = true; } if (isset($sort_direction)) { # Store the sorting direction in the session $search_data["products"]["sort_direction"] = $sort_direction; $flag_save = true; } if($current_area == 'C' && !empty($config['Appearance']['products_order']) && empty($search_data["products"]["sort_field"])) { $search_data["products"]["sort_field"] = $config['Appearance']['products_order']; $search_data["products"]["sort_direction"] = 0; } if (!empty($page) and $search_data["products"]["page"] != intval($page)) { # Store the current page number in the session $search_data["products"]["page"] = $page; $flag_save = true; } if (is_array($search_data["products"])) { $data = $search_data["products"]; foreach ($data as $k=>$v) if (!is_array($v) && !is_numeric($v)) $data[$k] = addslashes($v); } if(!isset($condition) || (isset($HTTP_GET_VARS['condition']) || isset($HTTP_POST_VARS['condition']) || isset($HTTP_COOKIE_VARS['condition']))) $condition = array(); if(!isset($join) || (isset($HTTP_GET_VARS['join']) || isset($HTTP_POST_VARS['join']) || isset($HTTP_COOKIE_VARS['join']))) $join = array(); if(!isset($add_fields) || (isset($HTTP_GET_VARS['add_fields']) || isset($HTTP_POST_VARS['add_fields']) || isset($HTTP_COOKIE_VARS['add_fields']))) $add_fields = array(); if(!isset($having) || (isset($HTTP_GET_VARS['having']) || isset($HTTP_POST_VARS['having']) || isset($HTTP_COOKIE_VARS['having']))) $having = array(); if(!isset($search_condition) || (isset($HTTP_GET_VARS['search_condition']) || isset($HTTP_POST_VARS['search_condition']) || isset($HTTP_COOKIE_VARS['search_condition']))) $search_condition = ""; $search_condition .= "$sql_tbl[pricing].productid=$sql_tbl[products].productid AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].membership IN ('".@$user_account['membership']."','')"; if($current_area == 'C' && !empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[pricing].variantid = 0 OR ($sql_tbl[variants].variantid = $sql_tbl[pricing].variantid".(($config["General"]["disable_outofstock_products"] == "Y" && $config["General"]["unlimited_products"] != "Y")?" AND $sql_tbl[variants].avail > 0":"")."))"; } else { $search_condition .= " AND $sql_tbl[pricing].variantid = 0"; } $data["substring"] = trim($data["substring"]); if (!empty($data["substring"])) { if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) { $search_data["products"]["by_title"] = $data["by_title"] = "Y"; $flag_save = true; } $ss = split(" ",$data["substring"]); $ss_condition = ""; $ss_count = 0; foreach($ss as $s) { #End Strip 'S' $s = trim($s); $start = (strlen($s)-1); if ((substr($s,$start,1)=="s")||(substr($s,$start,1)=="S")){ $s = substr($s,0,$start); } #End Strip 'S' # Search for substring in some fields... $condition = array(); if (!empty($data["by_title"])) { if($current_area == 'C' || $current_area == 'P') { $condition[] = "IF($sql_tbl[products_lng].product IS NOT NULL AND $sql_tbl[products_lng].product != '', $sql_tbl[products_lng].product, $sql_tbl[products].product) LIKE '%".$s."%'"; } else { $condition[] = "$sql_tbl[products].product LIKE '%".$s."%'"; } } if (!empty($data["by_shortdescr"])) { if($current_area == 'C' || $current_area == 'P') { $condition[] = "IF($sql_tbl[products_lng].descr IS NOT NULL AND $sql_tbl[products_lng].descr != '', $sql_tbl[products_lng].descr, $sql_tbl[products].descr) LIKE '%".$s."%'"; } else { $condition[] = "$sql_tbl[products].descr LIKE '%".$s."%'"; } } if (!empty($data["by_fulldescr"])) { if($current_area == 'C' || $current_area == 'P') { $condition[] = "IF($sql_tbl[products_lng].full_descr IS NOT NULL AND $sql_tbl[products_lng].full_descr != '', $sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) LIKE '%".$s."%'"; } else { $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$s."%'"; } } if (!empty($data["by_productcode"])) { if($current_area == 'C' || $current_area == 'P') { $condition[] = "IF($sql_tbl[products].productcode IS NOT NULL AND $sql_tbl[products].productcode != '', $sql_tbl[products].productcode, $sql_tbl[products].productcode) LIKE '%".$s."%'"; } else { $condition[] = "$sql_tbl[products].productcode LIKE '%".$s."%'"; } } if (!empty($data["extra_fields"]) && $active_modules['Extra_Fields']) { foreach($data["extra_fields"] as $k => $v) $condition[] = "($sql_tbl[extra_field_values].value LIKE '%".$s."%' AND $sql_tbl[extra_fields].fieldid = '$k')"; $join['extra_field_values'] = "$sql_tbl[products].productid = $sql_tbl[extra_field_values].productid"; $join['extra_fields'] = "$sql_tbl[extra_field_values].fieldid = $sql_tbl[extra_fields].fieldid AND $sql_tbl[extra_fields].active = 'Y'"; } #--------------------------This code is for Phrase Match--------------------------- if (!empty($condition)){ $ss_condition .= " AND (".implode(" OR ", $condition).")"; } } $search_condition .= $ss_condition; #-----------------------This code is for Any word match--------------------------- # if (!empty($condition)){ # if ($ss_count < 1){ # $ss_condition .= " AND ((".implode(" OR ", $condition).")"; # } else { # } # $ss_count++; # } # } # $ss_condition .=")"; # $search_condition .= $ss_condition; #--------------------------------------------------------------------------------------------- # Search statistics db_query("INSERT INTO $sql_tbl[stats_search] (search, date) VALUES ('$data[substring]', '".time()."')"); } # /if (!empty($data["substring"])) # # Search by product features # if(!empty($active_modules['Feature_Comparison'])) { include $xcart_dir."/modules/Feature_Comparison/search_define.php"; } # # Internation names & descriptions # if($current_area == 'C' || $current_area == 'P') { $add_fields[] = "$sql_tbl[products_lng].product as product_lng"; $add_fields[] = "$sql_tbl[products_lng].descr as descr_lng"; $add_fields[] = "$sql_tbl[products_lng].full_descr as fulldescr_lng"; $join['products_lng'] = "$sql_tbl[products_lng].productid = $sql_tbl[products].productid AND $sql_tbl[products_lng].code = '$shop_language'"; } if(!empty($data["manufacturers"]) && $active_modules['Manufacturers']) { $search_condition .= " AND $sql_tbl[products].manufacturerid IN ('".implode("','", $data["manufacturers"])."')"; } $search_condition .= " AND $sql_tbl[products_categories].productid=$sql_tbl[products].productid AND $sql_tbl[products_categories].categoryid = $sql_tbl[categories].categoryid"; if($current_area == 'C') { $search_condition .= " AND $sql_tbl[categories].membership IN ('','".addslashes(@$user_account['membership'])."')"; } $from_tbl[$sql_tbl["products_categories"]] = 1; $from_tbl[$sql_tbl["categories"]] = 1; if (!empty($data["categoryid"])) { # Search by category... $data["categoryid"] = intval($data["categoryid"]); $category_sign = ""; if (empty($data["category_main"]) && empty($data["category_extra"])) { $category_sign = "NOT"; } if (!empty($data["search_in_subcategories"])) { # Search also in all subcategories $categoryid_path = addslashes(func_query_first_cell("SELECT categoryid_path FROM $sql_tbl[categories] WHERE categoryid='".$data["categoryid"]."'")); $categoryids_tmp = func_query("SELECT categoryid FROM $sql_tbl[categories] WHERE categoryid='".$data["categoryid"]."' OR categoryid_path LIKE '$categoryid_path/%'"); if (is_array($categoryids_tmp) && !empty($categoryids_tmp)) { foreach ($categoryids_tmp as $k=>$v) { $categoryids[] = $v["categoryid"]; } $search_condition .= " AND $sql_tbl[products_categories].categoryid $category_sign IN (".implode(",", $categoryids).")"; } } else { $search_condition .= " AND $category_sign $sql_tbl[products_categories].categoryid='$data[categoryid]'"; } $condition = array(); if (!empty($data["category_main"])) $condition[] = "$sql_tbl[products_categories].main='Y'"; if (!empty($data["category_extra"])) $condition[] = "$sql_tbl[products_categories].main!='Y'"; if (!empty($condition)) $search_condition .= " AND (".implode(" OR ", $condition).")"; } elseif($current_area == 'C') { } # /if (!empty($data["categoryid"])) if (!empty($data["productcode"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].productcode LIKE '%".$data["productcode"]."%' OR $sql_tbl[variants].productcode LIKE '%".$data["productcode"]."%')"; } else { $search_condition .= " AND $sql_tbl[products].productcode LIKE '%".$data["productcode"]."%'"; } } if (!empty($data["productid"])) $search_condition .= " AND $sql_tbl[products].productid='".$data["productid"]."'"; if (!empty($data["provider"])) $search_condition .= " AND $sql_tbl[products].provider LIKE '%".$data["provider"]."%'"; if (!empty($data["price_min"])) { if(!empty($active_modules['Product_Options'])) { $having[] = "(price>='".$data["price_min"]."' OR v_price>='".$data["price_min"]."')"; # $search_condition .= " AND ($sql_tbl[pricing].price>='".$data["price_min"]."' OR v_pricing.price>='".$data["price_min"]."')"; } else { $search_condition .= " AND $sql_tbl[pricing].price>='".$data["price_min"]."'"; } } if (strlen(@$data["price_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $having[] = "(price<='".$data["price_max"]."' OR v_price<='".$data["price_max"]."')"; # $search_condition .= " AND ($sql_tbl[pricing].price<='".$data["price_max"]."' OR v_pricing.price<='".$data["price_max"]."')"; } else { $search_condition .= " AND $sql_tbl[pricing].price<='".$data["price_max"]."'"; } } if (!empty($data["avail_min"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].avail>='".$data["avail_min"]."' OR $sql_tbl[variants].avail>='".$data["avail_min"]."')"; } else { $search_condition .= " AND $sql_tbl[products].avail>='".$data["avail_min"]."'"; } } if (strlen(@$data["avail_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].avail<='".$data["avail_max"]."' OR $sql_tbl[variants].avail<='".$data["avail_max"]."')"; } else { $search_condition .= " AND $sql_tbl[products].avail<='".$data["avail_max"]."'"; } } if (!empty($data["weight_min"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].weight>='".$data["weight_min"]."' OR $sql_tbl[variants].weight>='".$data["weight_min"]."')"; } else { $search_condition .= " AND $sql_tbl[products].weight>='".$data["weight_min"]."'"; } } if (strlen(@$data["weight_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].weight<='".$data["weight_max"]."' OR $sql_tbl[variants].weight<='".$data["weight_max"]."')"; } else { $search_condition .= " AND $sql_tbl[products].weight<='".$data["weight_max"]."'"; } } if (!empty($data["forsale"])) $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."'"; if (!empty($data["flag_free_ship"])) $search_condition .= " AND $sql_tbl[products].free_shipping='".$data["flag_free_ship"]."'"; if (!empty($data["flag_ship_freight"])) $search_condition .= " AND $sql_tbl[products].shipping_freight='".$data["flag_ship_freight"]."'"; if (!empty($data["flag_ship_freight"])) { if ($data["flag_ship_freight"] == "Y") $search_condition .= " AND $sql_tbl[products].shipping_freight>'0'"; else $search_condition .= " AND $sql_tbl[products].shipping_freight='0'"; } if (!empty($data["flag_global_disc"])) $search_condition .= " AND $sql_tbl[products].discount_avail='".$data["flag_global_disc"]."'"; if (!empty($data["flag_free_tax"])) $search_condition .= " AND $sql_tbl[products].free_tax='".$data["flag_free_tax"]."'"; if (!empty($data["flag_min_amount"])) { if ($data["flag_min_amount"] == "Y") $search_condition .= " AND $sql_tbl[products].min_amount!='1'"; else $search_condition .= " AND $sql_tbl[products].min_amount='1'"; } if (!empty($data["flag_low_avail_limit"])) { if ($data["flag_low_avail_limit"] == "Y") $search_condition .= " AND $sql_tbl[products].low_avail_limit!='10'"; else $search_condition .= " AND $sql_tbl[products].low_avail_limit='10'"; } if (!empty($data["flag_list_price"])) { if ($data["flag_list_price"] == "Y") $search_condition .= " AND $sql_tbl[products].list_price!='0'"; else $search_condition .= " AND $sql_tbl[products].list_price='0'"; } if (!empty($data["flag_vat"])) { if ($data["flag_vat"] == "Y") $search_condition .= " AND $sql_tbl[products].vat!='0'"; else $search_condition .= " AND $sql_tbl[products].vat='0'"; } if (!empty($data["flag_gstpst"])) { if ($data["flag_gstpst"] == "Y") $search_condition .= " AND ($sql_tbl[products].apply_gst='Y' OR $sql_tbl[products].apply_pst='Y')"; else $search_condition .= " AND $sql_tbl[products].apply_gst='N' AND $sql_tbl[products].apply_pst='N'"; } if(!empty($active_modules['Product_Options'])) { $join['classes'] = "$sql_tbl[classes].productid = $sql_tbl[products].productid"; $join["variants"] = "$sql_tbl[variants].productid = $sql_tbl[products].productid"; $join["pricing v_pricing"] = "v_pricing.variantid = $sql_tbl[variants].variantid AND v_pricing.quantity = 1 AND v_pricing.membership IN ('','".@$user_account['membership']."')"; $add_fields[] = "IF($sql_tbl[variants].variantid IS NOT NULL,'Y','') as is_variant"; $add_fields[] = "IF($sql_tbl[classes].classid IS NOT NULL,'Y','') as is_product_options"; $add_fields[] = "v_pricing.price as v_price"; } if (!empty($data["sort_field"])) { # Sort the search results... $direction = ($data["sort_direction"] ? "DESC" : "ASC"); switch ($data["sort_field"]) { case "productcode": $sort_string = "$sql_tbl[products].productcode $direction"; break; case "title": $sort_string = "$sql_tbl[products].product $direction"; break; case "orderby": $sort_string = "$sql_tbl[products_categories].orderby $direction"; break; case "quantity": $sort_string = "$sql_tbl[products].avail $direction"; break; case "price": if (!empty($active_modules["Special_Offers"]) && !empty($search_data["products"]["show_special_prices"])) { $sort_string = "x_special_price $direction, price $direction"; } else { $sort_string = "price $direction"; } break; default: $sort_string = "$sql_tbl[products].product"; } } else { $sort_string = "$sql_tbl[products].product"; } if(!empty($data['sort_condition'])) { $sort_string = $data['sort_condition']; } if ($config["General"]["unlimited_products"]=="N" && ($current_area == "C" || $current_area == "B") && $config["General"]["disable_outofstock_products"] == "Y") { $search_condition .= " AND ($sql_tbl[products].avail>0 OR $sql_tbl[products].product_type NOT IN ('','N')) "; } if (!empty($from_tbl) and is_array($from_tbl)) $from_tbl = ", ".implode(", ", array_keys($from_tbl)); # # Generate LEFT JOIN string # $join_string = ''; if(!empty($join) && @is_array($join)) { foreach($join as $k => $v) { list($name, $as) = explode(" ", $k); if(!empty($as)) $as = " as ".$as; $join_string .= " LEFT JOIN ".$sql_tbl[$name].$as." ON $v "; } } # # Generate HAVING string # $having_string = ''; if(!empty($having)) { $having_string = " HAVING ".implode(" AND ", $having); } # # Generate additional fields string # $add_fields_string = ''; if(!empty($add_fields) && @is_array($add_fields)) { $add_fields_string = ", ".implode(", ", $add_fields); } # # Calculate the number of rows in the search results # $_res = db_query("SELECT COUNT($sql_tbl[products].productid), MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string"); $total_items = db_num_rows($_res); db_free_result($_res); if ($total_items > 0) { $page = $search_data["products"]["page"]; # # Prepare the page navigation # if(!isset($objects_per_page)) { if ($current_area == "C" || $current_area == "B") $objects_per_page = $config["Appearance"]["products_per_page"]; else $objects_per_page = $config["Appearance"]["products_per_page_admin"]; } $total_nav_pages = ceil($total_items/$objects_per_page)+1; include $xcart_dir."/include/navigation.php"; # # Perform the SQL query and getting the search results # if (!empty($search_data["is_modify"])) { # # Get the products and go to modify them # $products = func_query("SELECT $sql_tbl[products].productid, MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string"); if (is_array($products)) { x_session_register("store_productids"); $store_productids = array(); foreach($products as $v) $store_productids[$v['productid']] = true; func_header_location("product_modify.php?mode=return"); } } else $products = func_query("SELECT $sql_tbl[products].*, MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string ORDER BY $sort_string, $sql_tbl[products].product ASC LIMIT $first_page, $objects_per_page"); if (!empty($products)) { foreach ($products as $k=>$v) { $products[$k]['taxed_price'] = $v['price']; } } if (!empty($products) and $current_area == "C") { x_session_register("cart"); foreach ($products as $k=>$v) { if(!empty($active_modules['Feature_Comparison'])) { $products[$k]['is_clist'] = func_check_comparison($v['productid']); } $in_cart = 0; if(!empty($cart['products'])) { foreach($cart['products'] as $cv) { if($cv['productid'] == $v['productid']) $in_cart += $cv['amount']; } $products[$k]['avail'] -= $in_cart; if($products[$k]['avail'] < 0) { $products[$k]['avail'] = 0; } } $products[$k]["tmbn_url"] = func_get_thumbnail_url($v["productid"]); if(!empty($v['product_lng'])) $products[$k]['product'] = $v['product_lng']; if(!empty($v['descr_lng'])) $products[$k]['descr'] = $v['descr_lng']; if(!empty($v['fulldescr_lng'])) $products[$k]['fulldescr'] = $v['fulldescr_lng']; unset($products[$k]['product_lng'], $products[$k]['descr_lng'], $products[$k]['fulldescr_lng']); if (!empty($active_modules["Special_Offers"]) && !empty($search_data["products"]["show_special_prices"])) { include $xcart_dir."/modules/Special_Offers/search_results_calculate.php"; } else { $products[$k]["taxes"] = func_get_product_taxes($products[$k], $login); } if($products[$k]['descr'] == strip_tags($products[$k]['descr'])) $products[$k]['descr'] = str_replace("\n"," ",$products[$k]['descr']); if($products[$k]['fulldescr'] == strip_tags($products[$k]['fulldescr'])) $products[$k]['fulldescr'] = str_replace("\n"," ",$products[$k]['fulldescr']); } if (!empty($active_modules["Special_Offers"]) && empty($search_data["products"]["show_special_prices"])) { func_offers_check_products($login, $current_area, $products); } } # Assign the Smarty variables $smarty->assign("navigation_script","search.php?mode=search"); $smarty->assign("products", $products); $smarty->assign("first_item", $first_page+1); $smarty->assign("last_item", min($first_page+$objects_per_page, $total_items)); } $smarty->assign("total_items",$total_items); $smarty->assign("mode", $mode); if ($flag_save) x_session_save("search_data"); } if (empty($search_data["products"]) && $current_area == 'C') { $search_data["products"]['productcode'] = $config['Search_products']['search_products_sku_d']; $search_data["products"]['price_min'] = preg_replace("/-.*$/", "", $config['Search_products']['search_products_price_d']); $search_data["products"]['price_max'] = preg_replace("/^.*-/", "", $config['Search_products']['search_products_price_d']); $search_data["products"]['weight_min'] = preg_replace("/-.*$/", "", $config['Search_products']['search_products_weight_d']); $search_data["products"]['weight_max'] = preg_replace("/^.*-/", "", $config['Search_products']['search_products_weight_d']); $search_data["products"]['categoryid'] = $config['Search_products']['search_products_category_d']; } if (!empty($active_modules['Feature_Comparison']) && $current_area != 'C' && $current_area != 'P') { $fclasses = func_query("SELECT $sql_tbl[feature_classes].*, IF($sql_tbl[feature_classes_lng].class IS NOT NULL, $sql_tbl[feature_classes_lng].class, $sql_tbl[feature_classes].class) as class FROM $sql_tbl[feature_classes] LEFT JOIN $sql_tbl[feature_classes_lng] ON $sql_tbl[feature_classes].fclassid = $sql_tbl[feature_classes_lng].fclassid AND $sql_tbl[feature_classes_lng].code = '$shop_language' WHERE $sql_tbl[feature_classes].avail = 'Y' ORDER BY $sql_tbl[feature_classes].orderby"); if(!empty($fclasses)) { $smarty->assign("fclasses", $fclasses); } } $smarty->assign("search_prefilled", $search_data["products"]); if($active_modules['Manufacturers']) { $manufacturers = func_query("SELECT * FROM $sql_tbl[manufacturers] WHERE avail = 'Y' ORDER BY orderby,manufacturer"); if($manufacturers) { array_unshift($manufacturers, array("manufacturerid" => '0', "manufacturer" => func_get_langvar_by_name("lbl_no_manufacturer"))); $tmp = explode("\n", $config['Search_products']['search_products_manufacturers_d']); foreach($manufacturers as $k => $v) { if(@in_array($v['manufacturerid'], (array)$search_data["products"]['manufacturers']) || (in_array($v['manufacturerid'], $tmp) && $current_area == 'C')) $manufacturers[$k]['selected'] = 'Y'; } if($manufacturers) $smarty->assign("manufacturers", $manufacturers); } } if($active_modules['Extra_Fields']) { $extra_fields = func_query("SELECT * FROM $sql_tbl[extra_fields] WHERE active = 'Y' ORDER BY field"); if($extra_fields) { $tmp = explode("\n", $config['Search_products']['search_products_extra_fields']); foreach($extra_fields as $k => $v) { if(!in_array($v['fieldid'], $tmp) && $current_area == 'C') { unset($extra_fields[$k]); continue; } if($search_data["products"]['extra_fields'][$v['fieldid']]) $extra_fields[$k]['selected'] = 'Y'; } if($extra_fields) $smarty->assign("extra_fields", $extra_fields); } } if($current_area != 'C') include $xcart_dir."/include/categories.php"; $search_categories = $smarty->get_template_vars("allcategories"); $smarty->assign("search_categories", $search_categories); if(!defined('IS_ROBOT')) $smarty->assign("sort_fields", $sort_fields); $smarty->assign("main","search"); ?>

Put this code in (search_results.tpl) to enable sku search in the "search by pattern" field
Located just under the form tag or with the other checkboxes.(bug fix 7/15/05 value"->value=")
Code:
<input type="hidden" name="by_productcode" value="checked"> or <input type="checkbox" name="by_productcode" value="checked">

To allow the simple search on the Home page To search SKU and Extra Fields
In (/customer/search.tpl) find the below:
Code:
<FORM method="POST" action="search.php" name="productsearchform"> <INPUT type="hidden" name="simple_search" value="Y"> <INPUT type="hidden" name="mode" value="search"> <INPUT type="hidden" name="posted_data[by_title]" value="Y"> <INPUT type="hidden" name="posted_data[by_shortdescr]" value="Y"> <INPUT type="hidden" name="posted_data[by_fulldescr]" value="Y">

Replace the above code with the belowUpdated 6/14/05) Added {if $v.fieldid ne ''}{/if} it cleans up the page source(not a bug fix)
Code:
<FORM name="searchform" action="search.php" method="POST"> <INPUT type="hidden" name="mode" value="search"> <INPUT type="hidden" name="posted_data[by_title]" value="checked"> <INPUT type="hidden" name="posted_data[by_shortdescr]" value="checked"> <INPUT type="hidden" name="posted_data[by_fulldescr]" value="checked"> <INPUT type="hidden" name="posted_data[by_productcode]" value="checked"> {if $active_modules.Extra_Fields && $extra_fields ne ''} {foreach from=$extra_fields item=v} {if $v.fieldid ne ''} <INPUT type="hidden" name="posted_data[extra_fields][{$v.fieldid}]" value="checked"> {/if} {/foreach} {/if}
__________________
\"Then again it could all be horse crap\"
by some old Guy.
4.013
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:17 AM.

   

 
X-Cart forums © 2001-2020