Update Customer::searchByName()
This commit is contained in:
@@ -808,7 +808,9 @@
|
||||
ajax: "1",
|
||||
tab: "AdminCustomers",
|
||||
action: "searchCustomers",
|
||||
customer_search: $('#customer').val()},
|
||||
customer_search: $('#customer').val(),
|
||||
skip_deleted: "1",
|
||||
},
|
||||
success : function(res)
|
||||
{
|
||||
if(res.found)
|
||||
|
||||
@@ -528,14 +528,16 @@ class CustomerCore extends ObjectModel
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Corresponding customers
|
||||
* @throws PrestaShopDatabaseException
|
||||
*/
|
||||
public static function searchByName($query, $limit = null)
|
||||
public static function searchByName($query, $limit = null, $skip_deleted = false)
|
||||
{
|
||||
$sql_base = 'SELECT *
|
||||
FROM `'._DB_PREFIX_.'customer`';
|
||||
$sql = '('.$sql_base.' WHERE `email` LIKE \'%'.pSQL($query).'%\' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
$sql .= ' UNION ('.$sql_base.' WHERE `id_customer` = '.(int)$query.' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
$sql .= ' UNION ('.$sql_base.' WHERE `lastname` LIKE \'%'.pSQL($query).'%\' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
$sql .= ' UNION ('.$sql_base.' WHERE `firstname` LIKE \'%'.pSQL($query).'%\' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
FROM `'._DB_PREFIX_.'customer`';
|
||||
$where_deleted = $skip_deleted ? ' AND `deleted` = 0' : '';
|
||||
|
||||
$sql = '('.$sql_base.' WHERE `email` LIKE \'%'.pSQL($query).'%\' '.$where_deleted.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
$sql .= ' UNION ('.$sql_base.' WHERE `id_customer` = '.(int)$query.' '.$where_deleted.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
$sql .= ' UNION ('.$sql_base.' WHERE `lastname` LIKE \'%'.pSQL($query).'%\' '.$where_deleted.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
$sql .= ' UNION ('.$sql_base.' WHERE `firstname` LIKE \'%'.pSQL($query).'%\' '.$where_deleted.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')';
|
||||
|
||||
if ($limit) {
|
||||
$sql .= ' LIMIT 0, '.(int)$limit;
|
||||
|
||||
@@ -1080,12 +1080,13 @@ class AdminCustomersControllerCore extends AdminController
|
||||
public function ajaxProcessSearchCustomers()
|
||||
{
|
||||
$searches = explode(' ', Tools::getValue('customer_search'));
|
||||
$skip_deleted = Tools::getValue('skip_deleted');
|
||||
$customers = array();
|
||||
$searches = array_unique($searches);
|
||||
foreach ($searches as $search) {
|
||||
if (!empty($search) && $results = Customer::searchByName($search, 50)) {
|
||||
if (!empty($search) && $results = Customer::searchByName($search, 50, $skip_deleted)) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['active'] && !$result['deleted']) {
|
||||
if ($result['active']) {
|
||||
$customers[$result['id_customer']] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user