Jump to content

Search for product within category (admin)


jasehead

Recommended Posts

Is there an easy way to add a text box and submit button to (admin) products.index.php so that admin can search within a category for matching products?  Just enough to change the submitted URL from admin_stuff.php?_g=products&cat_id=72 to admin_stuff.php?_g=products&q=searchtext&cat_id=72

Link to comment
Share on other sites

In admin, Products, there is a Filter drop-down selector where a single category can be selected. Only products that are associated with that category will be listed.

Then, there is a series of letters across the top of the table where only those products that the name starts with that letter will be shown.

If the two filtering mechanisms still show too great a number of products, you may need a solution to use the Search slide out box to enter a word(s) so that the AJAX call can fetch a suggested list of candidates based on what the AJAX call is programmed to search for. Which is not as restrictive as the filtering already in place.

That is because the search box is available at all times, not just when looking at the Product Inventory page.

It should be possible to add to the AJAX call and the core code that does the searching to incorporate the filters if present.

More later.

Link to comment
Share on other sites

I have been editing together the URL from the search and the filter to get a filtered search result.

What about a simple javascript that takes a textbox value and adds it to the URL?

window.location.search += 'q=searchboxtext';

 

Link to comment
Share on other sites

Something like this under the filter on products.index.php

<br><button onclick='window.location.search+="&q="+prompt("enter string:");'>Search</button>

Not working for me though (because I had it inside the exisiting form).  But the idea would be you filter for a category and  then tweak the results by searching for an item in that category.

Although I DID get it to work externally as a bookmarklet, so I'll use this for now:

javascript:window.location.search+="&q="+prompt("enter string:");

It is messy because it keeps appending and appending and appending to the URL, but only the last value gets used so it does work.  Also, I can search for multiple words in the same way as the search slide out box.

Link to comment
Share on other sites

You may want to try the following. This is my solution as I described above. Keep these directions as the edits will not survive an upgrade.

In /classes/ajax.class.php, near line 99, find:

        foreach ($GLOBALS['hooks']->load('class.ajax.search') as $hook) {
            include $hook;
        }

On a new blank line after that, add:

if ($type == "product") { if (!empty($_GET["cat_id"])) { $where['cat_id'] = $_GET['cat_id']; } if (!empty($_GET["char"])) { $where['name'] = "~=^[".$_GET['char']."]"; } }

Near line 129, find:

if (($results = $GLOBALS['db']->select('CubeCart_inventory', false, array('~'.$search_string => array('name', 'product_code')), false, 15, false, false)) !== false) {

Change to:

if (($results = $GLOBALS['db']->select('CubeCart_inventory', false, merge_array(array('~'.$search_string => array('name', 'product_code')),$where), false, 15, false, false)) !== false) {


In the file /classes/db/database.class.php, near line 921, find:

$where[] = implode(' OR ', $or);

Change to:

$where[] = "(".implode(' OR ', $or).")";

Near line 931, find:

case '~':
    // Fuzzy searching
    $symbol = 'LIKE';
    $value = "%{$match[2]}%";
    break;

After that, on a new blank line, add this:

case '~=':
    // RegExp searching
    $symbol = 'REGEXP';
    $value = "$match[2]";
    break;



In the admin skin file /js/admin.js, near line 118, find:

            function: "search"
        };
    $.get(a, n, function(t) {

Change to:

            function: "search"
        }; n = $.extend(n,{cat_id:$.urlParam('cat_id'),char:$.urlParam('char')});
    $.get(a, n, function(t) {

At line 1, on a new blank line, add this:

$.urlParam = function(name){
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results==null) { return null; } return decodeURI(results[1]) || 0;
}

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...