Druide Posted March 18, 2003 Share Posted March 18, 2003 MOD: Search Results with Highlight v1.0 By: Robert Hellemans NOTE: this mod is Case Sensitive !!! PREVIEW at LIVE store: http://www.ruddlesmills.com/advanced_searc...s=Case&x=30&y=7 LIVE STORE !!!: http://www.ruddlesmills.com no fake orders, you will be billed ! Difficulty: EASY INSTALL Time: Less then 1 minute Files to change: 1 catalog/includes/modules/product_listing.php Admin: to set a different background color for the searchresults, look at ADMIN > configuration > My Store > Search Result Highlight Color you can set to colorname like: yellow or this way: #FFFF00 What does it do ?: This little but effective MOD will Highlight the keywords that you have given in the search query. I made it so that it only checks the fields: products_name & products_model which should be more then enough because not many people have their descriptions listed in product_listing.php Let's start to have some fun !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! insert into your database: INSERT INTO configuration VALUES ('', 'Search Result Highlight Color', 'SEARCH_RESULT_BACKGROUND_COLOR', 'yellow', 'This will be the background color from the matching keywords in searchresults<br>This is Case Sensitive !', 1, 7000, NULL, '2003-03-18 11:05:37', NULL, NULL); find in catalog/includes/modules/product_listing.php case 'PRODUCT_LIST_MODEL': $lc_text = ' ' . $listing_values['products_model'] . ' '; break; case 'PRODUCT_LIST_NAME': if ($HTTP_GET_VARS['manufacturers_id']) { $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>'; } else { $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $listing_values['products_name'] . '</a> '; } break; REPLACE WITH: case 'PRODUCT_LIST_MODEL': $fldname = $listing_values['products_model']; if ($HTTP_GET_VARS['keywords'] != "" ) { $string_to_split = $HTTP_GET_VARS['keywords']; $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); } $lc_text = ' ' . $fldname . ' '; break; case 'PRODUCT_LIST_NAME': if ($HTTP_GET_VARS['manufacturers_id']) { $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>'; } else { $fldname = $listing_values['products_name']; if ($HTTP_GET_VARS['keywords'] != "" ) { $string_to_split = $HTTP_GET_VARS['keywords']; $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); } $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $fldname . '</a> '; } break; i couldn't make it easier for you all, sorry for that ;) Let me know if you liked it ! Quote Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
bolivia Posted March 19, 2003 Share Posted March 19, 2003 Hi. I like your feature, I am using version 2.2 Loaded sql fine but on a product search all descriptions dissapear. Is it possible to email me a copy of your product_listing.php Maybee while pasting the code something goes wrong. Thanks Luis [email protected] Quote Link to comment Share on other sites More sharing options...
Druide Posted March 19, 2003 Author Share Posted March 19, 2003 or get it here http://www.oscommerce.com/community/contributions,1086 Quote Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
Druide Posted March 19, 2003 Author Share Posted March 19, 2003 Hi.I like your feature, I am using version 2.2 Loaded sql fine but on a product search all descriptions dissapear. Is it possible to email me a copy of your product_listing.php Maybee while pasting the code something goes wrong. Thanks Luis [email protected] the code is correct, i have verified it i think one of your installed MODS is making the error It's just NOT POSSIBLE that the code is not right, sorry... I am just 110% sure about this one --------------- check your original file, i hope you did a backup (you should do that ANY TIME you install a MOD) here is my piece of code to verify yours switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $fldname = $listing_values['products_model']; if ($HTTP_GET_VARS['keywords'] != "" ) { $string_to_split = $HTTP_GET_VARS['keywords']; $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); } $lc_text = ' ' . $fldname . ' '; break; case 'PRODUCT_LIST_NAME': if ($HTTP_GET_VARS['manufacturers_id']) { $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>'; } else { $fldname = $listing_values['products_name']; if ($HTTP_GET_VARS['keywords'] != "" ) { $string_to_split = $HTTP_GET_VARS['keywords']; $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); } $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $fldname . '</a> '; } break; case 'PRODUCT_LIST_DESCRIPTION': $lc_text = ' ' . osc_trunc_string(strip_tags($listing_values['products_description'], '<a><b><em><font><i><s><span><strong><sub><sup><u>'), PRODUCT_LIST_DESCRIPTION_LENGTH) . ' '; $col_to_span = sizeof($column_list)-1; if (PRODUCT_LIST_IMAGE > 0) { $col_to_span -= 1; } $lc_params = 'colspan="' . $col_to_span . '" '; break; case 'PRODUCT_LIST_MANUFACTURER': $lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing_values['manufacturers_id'], 'NONSSL') . '">' . $listing_values['manufacturers_name'] . '</a> '; break; case 'PRODUCT_LIST_PRICE': $lc_align = 'right'; if ($listing_values['specials_new_products_price']) { $lc_text = ' <s>' . $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($listing_values['specials_new_products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</span> '; } else { $lc_text = ' ' . $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . ' '; } break; NOTE: it not the whole file ! only a piece Quote Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
xuechao Posted March 19, 2003 Share Posted March 19, 2003 Druide, thanks for the cool mod, but for some reason, the highlight is not shown on the search result. Currently I am using the latest snapshot along with the Description mod. any idea? thanks Quote Link to comment Share on other sites More sharing options...
Waza04 Posted March 19, 2003 Share Posted March 19, 2003 I have been having a few probs with this - sometimes it higlights sometimes it dosent!! Dont know why!!! Warren Quote Link to comment Share on other sites More sharing options...
Druide Posted March 19, 2003 Author Share Posted March 19, 2003 did you read the line: NOTE: this mod is Case Sensitive !!! that means if you search for: Case like i do show in the preview URL it only highlight when 'Case' is found, and NOT when 'case' is found. That is why you dont see it always i think ;) Quote Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
Druide Posted March 19, 2003 Author Share Posted March 19, 2003 Druide, thanks for the cool mod, but for some reason, the highlight is not shown on the search result. Currently I am using the latest snapshot along with the Description mod. any idea? thanks where is your site or code (not whole file !) what you have added ? I cannot look through walls, still trying to make a MOD for that one....lol Quote Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
xuechao Posted March 20, 2003 Share Posted March 20, 2003 did you read the line: NOTE: this mod is Case Sensitive !!! that means if you search for: Case like i do show in the preview URL it only highlight when 'Case' is found, and NOT when 'case' is found. That is why you dont see it always i think ;) Sorry, I have forgotten it's Case Sensitive. It works smoothly now. Is it possible for to highlight the description as well? I cannot look through walls, still trying to make a MOD for that one Can't wait to see try out this MOD. :P Once again, thanks for this awesome mod! Quote Link to comment Share on other sites More sharing options...
Druide Posted March 20, 2003 Author Share Posted March 20, 2003 Sorry, I have forgotten it's Case Sensitive. How could you have forgotten that, you have just installed it ??? I hope you do not forget to install the MODS 'completely' :roll: Is it possible for to highlight the description as well? Yes that is possible but i dont know the variables from MS1, need to know all the values & names of the variables. But i dont have too much time for that, just look at the code, it's really simple to add it yourself, but BACKUP before you start to try... One day you will be happy that you started coding PHP Quote Robert We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;) Link to comment Share on other sites More sharing options...
kastle Posted April 13, 2003 Share Posted April 13, 2003 I happen to be messing around with this on MS1, and couldn't get the damned thing to work... But I have figured it out... The variable $listing_values no longer exists in MS1... It's now $listing So the contrib, for MS1, should look like this... case 'PRODUCT_LIST_MODEL': $fldname = $listing['products_model']; if ($HTTP_GET_VARS['keywords'] != "" ) { $HTTP_GET_VARS['keywords'] = strtolower($HTTP_GET_VARS['keywords']); $string_to_split = strtoupper($HTTP_GET_VARS['keywords']); // is result UPPERCASE ? $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); $string_to_split = $HTTP_GET_VARS['keywords']; // is result LOWERCASE ? $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); $string_to_split = ucwords($HTTP_GET_VARS['keywords']); // is result starting with 1 uppercase and rest is lowercase ? $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); } $lc_text = ' ' . $fldname . ' '; break; case 'PRODUCT_LIST_NAME': if ($HTTP_GET_VARS['manufacturers_id']) { $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>'; } else { $fldname = $listing['products_name']; if ($HTTP_GET_VARS['keywords'] != "" ) { $HTTP_GET_VARS['keywords'] = strtolower($HTTP_GET_VARS['keywords']); $string_to_split = strtoupper($HTTP_GET_VARS['keywords']); // is result UPPERCASE ? $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); $string_to_split = $HTTP_GET_VARS['keywords']; // is result LOWERCASE ? $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); $string_to_split = ucwords($HTTP_GET_VARS['keywords']); // is result starting with 1 uppercase and rest is lowercase ? $tok = split(" ", $string_to_split); $size = sizeof($tok); for ($i = 0; $i < $size; $i++) $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); } $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $fldname . '</a> '; } break; EDITED: Edited for readability. Thanks, Linda Quote Link to comment Share on other sites More sharing options...
Eliot Rayner Posted April 25, 2003 Share Posted April 25, 2003 Hi thanks for a great contribution. i think i have found a bug though. if you do a search on 'un' on a standard install of OSC with the standard products loaded in the catalog, and you've chosen to see 'Product Model' in Admin->Configuration->Product Listing you get some strange results in the search results .... I think it has something to do with the following similar lines of code in catalogincludesmodulesproduct_listing.php within the case 'PRODUCT_LIST_MODEL': statement around line 123 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); has anyone got any ideas where to change the code ? tia Quote Link to comment Share on other sites More sharing options...
Waza04 Posted April 25, 2003 Share Posted April 25, 2003 Sorry - I dont seam to have the problem!! Warren Quote Link to comment Share on other sites More sharing options...
Waza04 Posted April 25, 2003 Share Posted April 25, 2003 Sorry - Yes I DO!!! Dont know how to fix it though!! Warren Quote Link to comment Share on other sites More sharing options...
PopTheTop Posted January 7, 2005 Share Posted January 7, 2005 I do not have a problem with that, seems to work fine at http://www.popthetop.com/catalog/index.php Quote L8r, PopTheTop Published osC Contributions: - eCheck Payment Module v3.1 - Reviews in Product Display v2.0 - Fancier Invoice & Packingslip v6.1 - Admin Notes / Customer Notes v2.2 - Customer Zip & State Validation v2.2 - Search Box with Dropdown Category Menu v1.0 Pop your camper's top today! It's a popup thing... You wouldn't understand Link to comment Share on other sites More sharing options...
Mitch007 Posted May 2, 2005 Share Posted May 2, 2005 I do not have a problem with that, seems to work fine at http://www.popthetop.com/catalog/index.php <{POST_SNAPBACK}> Hi I was just on you online-shop (www.popthetop.com) and I tried to search with "camp c" on the quick find. The result has the same error on the column "SKU#" like I do have in my shop. I tried to find out the error in the code, but I'm not really that good in programming :blush: Hope you can help me out. Sincerely, Jimi Quote Link to comment Share on other sites More sharing options...
PopTheTop Posted May 2, 2005 Share Posted May 2, 2005 Wow, I do have that problem after all. What is causing that??? Quote L8r, PopTheTop Published osC Contributions: - eCheck Payment Module v3.1 - Reviews in Product Display v2.0 - Fancier Invoice & Packingslip v6.1 - Admin Notes / Customer Notes v2.2 - Customer Zip & State Validation v2.2 - Search Box with Dropdown Category Menu v1.0 Pop your camper's top today! It's a popup thing... You wouldn't understand Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.