How to add “Product Code” as an additional default search parameter to default “Product name” in SEARCH (w/o using “ADVANCE SEARCH”)?
[quote name=‘aerofan’]How to add “Product Code” as an additional default search parameter to default “Product name” in SEARCH (w/o using “ADVANCE SEARCH”)?[/QUOTE]
we add it to the ‘Search Words’ on the product screen
Thanks Catch1fish, it works!
Note: this need to be copied into every language in use.
Anyone knows how to modify the code containing the “Search function” adding “Product Code” field into default “Search”?
[quote name=‘aerofan’]Thanks Catch1fish, it works!
Note: this need to be copied into every language in use.
Anyone knows how to modify the code containing the “Search function” adding “Product Code” field into default “Search”?[/QUOTE]
add…
$tmp .= db_quote(" OR products.product_code LIKE ?l", "%$piece%");
before
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?l", "%$piece%");
}
if ($params['pshort'] == 'Y') {
$tmp .= db_quote(" OR descr1.short_description LIKE ?l", "%$piece%");
}
if ($params['pfull'] == 'Y') {
$tmp .= db_quote(" OR descr1.full_description LIKE ?l", "%$piece%");
}
if ($params['pkeywords'] == 'Y') {
$tmp .= db_quote(" OR (descr1.meta_keywords LIKE ?l OR descr1.meta_description LIKE ?l)", "%$piece%", "%$piece%");
}
if (!empty($params['feature']) && $params['action'] != 'feature_search') {
$tmp .= db_quote(" OR ?:product_features_values.value LIKE ?l", "%$piece%");
}
in core/fn.core.php file
near lines 2700 in the fn_get_products function
I think this only works if your searching only products (not pages/other) there is a setting in the backend for it.
Thanks for your help.
Right Miracles: searching for “search” in kb2 returns solution at point 7.
For others reading this post: let me reproduce the kb2 hint:
Look for file named: core/fn.catalog.php
Search for:
foreach ($pieces as $piece) {
$tmp = db_quote("(descr1.search_words LIKE ?s)", "%$piece%"); // check search words
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?s", "%$piece%");
}
if ($params['pshort'] == 'Y') {
$tmp .= db_quote(" OR descr1.short_description LIKE ?s", "%$piece%");
}
Replace with
foreach ($pieces as $piece) {
$tmp = db_quote("(descr1.search_words LIKE ?s)", "%$piece%"); // check search words
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?s", "%$piece%");
}
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR products.product_code LIKE ?s", "%$piece%");
}
if ($params['pshort'] == 'Y') {
$tmp .= db_quote(" OR descr1.short_description LIKE ?s", "%$piece%");
}
Thank you! That’s why i need too!
[quote name=‘aerofan’]Thanks for your help.
Right Miracles: searching for “search” in kb2 returns solution at point 7.
For others reading this post: let me reproduce the kb2 hint:
Look for file named: core/fn.catalog.ph (not core/fn.core.php)
Search for:
foreach ($pieces as $piece) {
$tmp = db_quote("(descr1.search_words LIKE ?s)", "%$piece%"); // check search words
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?s", "%$piece%");
}
if ($params['pshort'] == 'Y') {
$tmp .= db_quote(" OR descr1.short_description LIKE ?s", "%$piece%");
}
Replace with
foreach ($pieces as $piece) {
[/QUOTE]
$tmp = db_quote("(descr1.search_words LIKE ?s)", "%$piece%"); // check search words
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?s", "%$piece%");
}
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR products.product_code LIKE ?s", "%$piece%");
}
if ($params['pshort'] == 'Y') {
$tmp .= db_quote(" OR descr1.short_description LIKE ?s", "%$piece%");
}
Its possible modify this for searching sub-category inside category?
Thank you for pointing out the Knowledge Base Miracles. For some reason I forget to check there. By the way the code changed between what is in the knowledge base and what is in 2.0.8.
I did this by changing core/fn.catalog.php
I added:
if ($params['pshort'] == 'Y') {
$tmp .= db_quote(" OR descr1.short_description LIKE ?l", "%$piece%");
}
After:
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR products.product_code LIKE ?s", "%$piece%");
}
Brandon
I hate to add to an old post but if you are wanting to do this with v4.2.2 here is the changes to the code I made…
Open fn.catalog.php
Add…
// Added by chris to allow searches on product code
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR products.product_code LIKE ?l", '%' . $piece . '%');
}
Just After…
$_condition = array();
foreach ($pieces as $piece) {
if (strlen($piece) == 0) {
continue;
}
$tmp = db_quote("(descr1.search_words LIKE ?l)", '%' . $piece . '%'); // check search words
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?l", '%' . $piece . '%');
}
Or you can simply install our free Search Improvements module which also allow to make search by the product code of product option combinations. Thanks