Jump to content

new feature idea


keat
 Share

Recommended Posts

In the admin side, the ability to search by product code or description.

EG, a lot of my products have codes along the lines RC1, RC2, RC3 etc

Searching for an RC product code reveeals anything with an RC in the name or code, so will show products like reinforced tube, or electrcitians screwdriver

 

Link to comment
Share on other sites

Please try these edits. This enhancement will add three checkboxes below the text entry field for the Search Products on the slide-out Search box in admin.

Using these checkboxes, the admin can specify which of the three sources to search in: Name, Product Code, and/or Description.

For example, if you need to search for all products where the word 'drywall' is in the description - regardless if it were to be part of the product name or code.

There are four edits: the admin skin template common.search.php, the admin skin javascript file admin.js, the admin source file products.index.inc.php, and the class file ajax.class.php.

These edits affect both the ajax-based "fetch suggestions" (aka auto-complete), as well as the "Go" button.

common.search.php:

Near line 15, find:

<h4>{$LANG.search.title_search_products}</h4>
<input type="text" name="search[product]" placeholder="&#xF002; {$LANG.common.type_to_search}" id="product" class="textbox left ajax" rel="product">
<input type="submit" value="{$LANG.common.go}" class="go_search">


Add after:

<table width="100%"><tr>
<td width="33%"><input type="checkbox" name="search[product_n]" id="product_n" checked="checked"> Name</td>
<td width="33%"><input type="checkbox" name="search[product_c]" id="product_c" checked="checked"> Code</td>
<td width="33%"><input type="checkbox" name="search[product_d]" id="product_d"> Desc</td>
</tr></table>

(Note: the Description checkbox is not normally checked so that this search box's behavior matches the original behavior. If all three boxes are unchecked, the search falls back to the original columns to look in: name and product_code.)

admin.js:

Near line 128, find:

function ajaxSuggest(t, e, i) {
    var a = "./" + $("#val_admin_file").text(),
        n = {
            _g: "xml",
            type: i,
            q: t,
            function: "search"
        };


Change to:

function ajaxSuggest(t, e, i) {
    var a = "./" + $("#val_admin_file").text(),
        pn = (!0 == $("#product_n").prop("checked") ? "|N" : ""),
        pc = (!0 == $("#product_c").prop("checked") ? "|C" : ""),
        pd = (!0 == $("#product_d").prop("checked") ? "|D" : ""),
        n = {
            _g: "xml",
            type: i,
            q: t + pn + pc + pd,
            function: "search"
        };

(Note: your browser will most likely use its cached copy of admin.js, so be sure to force your browser to reload page resources. This is usually done with CTRL-F5.)

products.index.inc.php:

Near line 1172, find:

    // Get inventory
    $page  = (isset($_GET['page'])) ? $_GET['page'] : 1;
    $per_page = 20;
    if (isset($_GET['char']) && !empty($_GET['char'])) {
        $where  =  "`name` REGEXP '^[".$_GET['char']."]'";
    } elseif (isset($_GET['q']) && !empty($_GET['q'])) {
        $where = "(`name` LIKE '%".$_GET['q']."%' OR `product_code` LIKE '%".$_GET['q']."%')";


Replace that last line:

        $where = "(`name` LIKE '%".$_GET['q']."%' OR `product_code` LIKE '%".$_GET['q']."%')";

With this:

$tmp_search_string_array = explode("|",$_GET['q'],2);
$_GET['q'] = $tmp_search_string_array[0];
$look_in_columns = $tmp_search_string_array[1]??"";
$product_table_columns = array('name' => 'N', 'product_code' => 'C', 'description' => 'D');
if (empty($look_in_columns)) {
	$product_columns = array('name', 'product_code');
} else {
	$product_columns_array = explode("|",$look_in_columns);
	$product_columns = array_keys(array_intersect($product_table_columns,$product_columns_array));
}
$where = $GLOBALS['db']->where('CubeCart_inventory',array('~'.$_GET['q'] => $product_columns));
$where = "(".preg_replace("/^WHERE /",'',$where,1).")";


Near line 20, find:

if (isset($_POST['search']) && !empty($_POST['search'])) {
    if (is_numeric($_POST['search']['product_id'])) {
        httpredir('?_g=products&action=edit&product_id='.$_POST['search']['product_id']);
    } else { 


Add after:

if(isset($_POST['search']['product_n'])) {$_POST['search']['product'] .= "|N";}
if(isset($_POST['search']['product_c'])) {$_POST['search']['product'] .= "|C";}
if(isset($_POST['search']['product_d'])) {$_POST['search']['product'] .= "|D";}

ajax.class.php:

Near line 144, find:

            case 'product':
                // Limited to a maximum of 15 results, in order to prevent it going mental
                if (($results = $GLOBALS['db']->select('CubeCart_inventory', false, array('name', 'product_code')), false, 15, false, false)) !== false) {


Change to:

            case 'product':
$product_table_columns = array('name' => 'N', 'product_code' => 'C', 'description' => 'D');
if (empty($look_in_columns)) {
	$product_columns = array('name', 'product_code');
} else {
	$product_columns_array = explode("|",$look_in_columns);
	$product_columns = array_keys(array_intersect($product_table_columns,$product_columns_array));
}
                // Limited to a maximum of 15 results, in order to prevent it going mental
                if (($results = $GLOBALS['db']->select('CubeCart_inventory', false, array('~'.$search_string => $product_columns), false, 15, false, false)) !== false) {


Near line 113, find:

    public static function search($type, $search_string)
    {
        $data = false;

Add after:

$tmp_search_string_array = explode("|",$search_string,2);
$search_string = $tmp_search_string_array[0];
$look_in_columns = $tmp_search_string_array[1]??"";

(Note: the above edit requires PHP7.)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...