VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: Jason Farmer on October 17, 2012, 11:35:22 AM

Title: Admin: List Orders - Search is not correct...
Post by: Jason Farmer on October 17, 2012, 11:35:22 AM
A minor bug ...
vm 2.0.12
administrator\components\com_virtuemart\models\orders.php from Line 216

$where[] = implode (' LIKE '.$search.' OR ', $searchFields) . ' LIKE '.$search.' ';

should include braces around the whole thing .. ie.

$where[] = '('.implode (' LIKE '.$search.' OR ', $searchFields) . ' LIKE '.$search.') ';

as this $where[] array gets imploded with ' AND ' later on

although its not written very clearly (imho)

I've changed this search on my installation to be case insensitive and made the code a little more clear
              $search = $this->_db->getEscaped( strtoupper($search), true );
$searchFields = array();
$searchFields[] = 'o.order_number';
$searchFields[] = 'u.company';
$searchFields[] = 'u.email';
$searchFields[] = 'u.phone_1';
$searchFields[] = 'u.address_1';
$searchFields[] = 'u.zip';
$searchFields[] = 'CONCAT_WS(" ",u.first_name,u.last_name)';
$searchFields[] = 'CONCAT_WS(" ",u.first_name,u.middle_name,u.last_name)';

$expandSQL = function($search) {
        return function($field) use ($search) {
        return 'UPPER('.$field.') LIKE "%'.$search.'%"';
        };
};

$where[] = '('.implode(' OR ', array_map($expandSQL($search),$searchFields)).')';