Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How To Make Select2 On Backend Search Any Of These Word Not Exact Phrase Rate Topic   - - - - -

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 351 posts

Posted 26 October 2021 - 10:29 PM #1

When you want to choose a category for an item on the backend the you have the option to search the select box using select2 js, but this search only accept "exact phrase" how can i switch it to "any of these words", thank you



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22386 posts

Posted 27 October 2021 - 04:41 AM #2

app/functions/fn.categories.php

 

You should replace

$condition .= db_quote(' AND ?:category_descriptions.category LIKE ?l', '%' . trim($params['search_query']) . '%');

to

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

(!) Not tested


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 351 posts

Posted 27 October 2021 - 08:00 AM #3

This is awesome, since your untested codes work this good, I wonder what the tested one will do, thank you so much!!!  :grin:  :mrgreen:



 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 351 posts

Posted 30 November 2021 - 09:23 PM #4

How can I make it to search only text and not numbers

 

app/functions/fn.categories.php

 

You should replace

$condition .= db_quote(' AND ?:category_descriptions.category LIKE ?l', '%' . trim($params['search_query']) . '%');

to

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

(!) Not tested



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22386 posts

Posted Yesterday, 05:02 AM #5

Try something like

 

$query_pieces = fn_explode(' ', $params['search_query']);
$search_conditions = array();
foreach ($query_pieces as $piece) {
    if (is_numeric($piece)) continue;
    $search_conditions[] =  db_quote(" ?:category_descriptions.category LIKE ?l ", '%' . $piece . '%');
}
$condition .= ' AND (' . implode(' OR ', $search_conditions) . ') ';

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 351 posts

Posted Yesterday, 07:58 AM #6

Works 100%, thank you!