Forums / Bug Reports / Searching orders for product name

Searching orders for product name

Views: 386

Results 1 to 3 of 3
26 Aug 2019, 4:56 PM
#1
edadk avatar

edadk

Zen Follower

Join Date:
Nov 2008
Posts:
191
Plugin Contributions:
0

Searching orders for product name

php7.2
zencart 1.56c
mysql 5.7x

Not sure if this is a bug or by design -

When using the product search box to search through orders, results are only returned if the searched word or phrase is at the beginning of the product title.

For example, let's say I've sold some Blue Widgets and some Green Widgets. If I use the orders product search to find orders where I've sold "Widgets" (of any kind), I get no results at all because Widgets is not at the beginning of the product title.

Searching for "Blue Widgets" or "Green Widgets" works fine since those words appear at the beginning of the product title but searching for a word that is contained in the product title but is not at the beginning does not return a result.

Ed

26 Aug 2019, 8:13 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,111
Plugin Contributions:
56

Re: Searching orders for product name

'tis a bug. Edit /admin/orders.php, locating this section (starting at line 872 in the as-shipped zc156c version):

// create search_orders_products filter
                  $search = '';
                  $search_distinct = ' ';
                  $new_table = '';
                  $new_fields = '';
                  if (isset($_GET['search_orders_products']) && zen_not_null($_GET['search_orders_products'])) {
                    $search_distinct = ' distinct ';
                    $new_table = " left join " . TABLE_ORDERS_PRODUCTS . " op on (op.orders_id = o.orders_id) ";
                    $keywords = zen_db_input(zen_db_prepare_input($_GET['search_orders_products']));
                    $search = " and (op.products_model like '%" . $keywords . "%' or op.products_name like '" . $keywords . "%')";
                    if (substr(strtoupper($_GET['search_orders_products']), 0, 3) == 'ID:') {
                      $keywords = TRIM(substr($_GET['search_orders_products'], 3));
                      $search = " and op.products_id ='" . (int)$keywords . "'";
                    }
                  } else {

... and change to

// create search_orders_products filter
                  $search = '';
                  $search_distinct = ' ';
                  $new_table = '';
                  $new_fields = '';
                  if (isset($_GET['search_orders_products']) && zen_not_null($_GET['search_orders_products'])) {
                    $search_distinct = ' distinct ';
                    $new_table = " left join " . TABLE_ORDERS_PRODUCTS . " op on (op.orders_id = o.orders_id) ";
                    $keywords = zen_db_input(zen_db_prepare_input($_GET['search_orders_products']));
                    $search = " and (op.products_model like '%" . $keywords . "%' or op.products_name like '[B]%[/B]" . $keywords . "%')";
                    if (substr(strtoupper($_GET['search_orders_products']), 0, 3) == 'ID:') {
                      $keywords = TRIM(substr($_GET['search_orders_products'], 3));
                      $search = " and op.products_id ='" . (int)$keywords . "'";
                    }
                  } else {
27 Aug 2019, 1:18 AM
#3
edadk avatar

edadk

Zen Follower

Join Date:
Nov 2008
Posts:
191
Plugin Contributions:
0

Re: Searching orders for product name

Thank you. That fixed if for me.