diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index 766b3eb33..e996f5bf4 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -810,7 +810,9 @@ ajax: "1", tab: "AdminCustomers", action: "searchCustomers", - customer_search: $('#customer').val()}, + customer_search: $('#customer').val(), + skip_deleted: "1", + }, success : function(res) { if(res.found) diff --git a/classes/Customer.php b/classes/Customer.php index e3e0fd39d..a8c4c3609 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -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; diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 695de6a3b..0cd3b910f 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -1095,10 +1095,11 @@ 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']) { $customers[$result['id_customer']] = $result;