jonas Posted July 6, 2016 Share Posted July 6, 2016 I have been trying to make an override for the search function in the backoffice so I can search for "company" in ps_customer. If someone calls we can not expect them to know their account e-mail or name. Anyone else had a problem with this? Link to comment Share on other sites More sharing options...
shokinro Posted July 6, 2016 Share Posted July 6, 2016 If you are going to use the same Customer Search field on Order Creation (Add new order) page, then you will need look into /controllers/admin/AdminCustomersController.php. When you enter something, it calls ajaxProcessSearchCustomers() method of above class. And inside the method, you will it call Customer::searchByName($search, 50). So you will need override searchByName() method in file /classes/Customer.Php 1 Link to comment Share on other sites More sharing options...
jonas Posted July 6, 2016 Author Share Posted July 6, 2016 (edited) If you are going to use the same Customer Search field on Order Creation (Add new order) page, then you will need look into /controllers/admin/AdminCustomersController.php. When you enter something, it calls ajaxProcessSearchCustomers() method of above class. And inside the method, you will it call Customer::searchByName($search, 50). So you will need override searchByName() method in file /classes/Customer.Php Thank you! Solved! class Customer extends CustomerCore { /** * Light back office search for customers * * @param string $query Searched string * @param null|int $limit Limit query results * @return array|false|mysqli_result|null|PDOStatement|resource Corresponding customers * @throws PrestaShopDatabaseException */ public static function searchByName($query, $limit = null) { $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).')'; $sql .= ' UNION ('.$sql_base.' WHERE `company` LIKE \'%'.pSQL($query).'%\' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).')'; if ($limit) { $sql .= ' LIMIT 0, '.(int)$limit; } return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } Edited July 6, 2016 by jonas (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted July 6, 2016 Share Posted July 6, 2016 glad it helped, and thanks for sharing your code here. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now