How Can I Search by Product Code

I want to enable quick search to search by product code as well as the other fields. How can I accomplish this without requiring users to use “advanced search”?

See this Knowledge Base article:

[url]CS-Cart Documentation — CS-Cart 4.15.x documentation



Bob

This works, but it won’t search by option combination part number. Anybody have a way to add that?

[quote name=‘interfaceFactory’]This works, but it won’t search by option combination part number. Anybody of a way to add that?[/QUOTE]



I know, that stinks! I’ve just had to add the option part numbers to the search words field. It’s extra work, but it works.

Ugh…we’ll have to do that too if we can’t code it into the search.

Oh, you might want to index “product_code” for the table “cscart_products” for faster searching.

[quote name=‘interfaceFactory’]Ugh…we’ll have to do that too if we can’t code it into the search.[/QUOTE]



We ran into the same issue. When we imported our products we did not add the Product code to the “Search Words” field in the CSV file. So we wrote a simple SQL update to update the Search words to add the product code.



We updated the search_words column in cscart_product_descriptions with the product_code in cscart_products using the product_id to join the tables. Pretty simple and worked well for over 10,000 products.



Now when we add new products we make sure to put the code in the csv file or add it manually to the Search words.

I’ve also added the product codes to the Search Words field and it works really well. As far as I can see, this is the best way to go.

Ok, to add product code and product option code to your quick search, open core/fn.catalog.php and add


if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR products.product_code LIKE ?s", "%$piece%");
}
$occ = db_get_fields(" SELECT product_code FROM ?:product_options_inventory");
if (in_array($piece, $occ)) {
$pid = db_get_field(" SELECT product_id FROM ?:product_options_inventory WHERE product_code = '$piece'");
$tmp .= db_quote(" OR products.product_id LIKE ?s", "%$pid%");
}




after


if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?l", "%$piece%");
}

Works good for me. That should be a standard item or at the very least an admin option.



Thanks!

Good job interfaceFactory, and yes this functionality, like so many others, should have already been there!

I’m having some trouble getting the search by product option code to work. I found the KB article and this thread, but the code isn’t working for me. My product option code is “KL200 APP TW”. When I search for KL200, I get nothing. Suggestions?

Anyone else having trouble searching by option combination product code?