Jump to content

How to create new order in backoffice and search for company name


jonas

Recommended Posts

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

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

  • Like 1
Link to comment
Share on other sites

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 by jonas (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...