Jump to content

Back office custom order / Search customer by phone


prototypo

Recommended Posts

The problem with your idea is that phone number is linked to Address and not to Customer

You need to search by Phone->Address->Customer.

But the main problem is that Phone Number is not unique key, so every customer can add, for example Address with phone number 00000 (Example)

 

Link to comment
Share on other sites

17 minutes ago, Amantha Bill said:

The problem with your idea is that phone number is linked to Address and not to Customer

You need to search by Phone->Address->Customer.

But the main problem is that Phone Number is not unique key, so every customer can add, for example Address with phone number 00000 (Example)

 

Why don't you write a solution?
Of course, it is a small modification of the code !!!

Link to comment
Share on other sites

On 5/16/2020 at 12:13 AM, prototypo said:

In back office order of Prestashop 1.6 i want to search customers by mobile phone. By default you can search by name / email and birthday.

I cannot find the file and the search function to customize it.

Anyone knows where it is?

 

FTP:

1. open ./classes/Customer.php

2. find function: public static function searchByName

3. replace function to:

public static function searchByName($query, $limit = null)
    {
        $sql = 'SELECT a.*, b.phone, b.phone_mobile
                FROM `' . _DB_PREFIX_ . 'customer` a
                LEFT JOIN '._DB_PREFIX_.'address b ON (a.id_customer = b.id_customer)
                WHERE 1';
        $search_items = explode(' ', $query);
        $research_fields = array('a.id_customer', 'a.firstname', 'a.lastname', 'a.email', 'b.phone', 'b.phone_mobile');
        if (Configuration::get('PS_B2B_ENABLE')) {
            $research_fields[] = 'company';
        }

        $items = array();
        foreach ($research_fields as $field) {
            foreach ($search_items as $item) {
                $items[$item][] = $field . ' LIKE \'%' . pSQL($item) . '%\' ';
            }
        }

        foreach ($items as $likes) {
            $sql .= ' AND (' . implode(' OR ', $likes) . ') ';
        }

        $sql .= Shop::addSqlRestriction(Shop::SHARE_CUSTOMER);

        if ($limit) {
            $sql .= ' LIMIT 0, ' . (int) $limit;
        }

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
    }

4. save Customer.php

DONE 😉

 

Or create override Customer.php

Link to comment
Share on other sites

9 hours ago, Guest said:

By editing the code, you can search, for example, by city, street, etc.

Omg i asked only the file location and you gave me the total solution! Even with the file ready to download!!!!!!
Thank you so much! You are great!

Can you help me please for some more customizations just by giving me some informations and not the total solution again? :D

Link to comment
Share on other sites

After all, by comparing the function in the original and the modified function, you can see the difference, which perhaps does not need an explanation.
Do you want to add eg a city:
in the SQL query you add b.city and in the array research_fields you also add b.city.

Link to comment
Share on other sites

7 hours ago, Guest said:

After all, by comparing the function in the original and the modified function, you can see the difference, which perhaps does not need an explanation.
Do you want to add eg a city:
in the SQL query you add b.city and in the array research_fields you also add b.city.

Yes i understand what you did! I made some customizations bymyself in other functions and i learned how it works. For example, i managed to add fields "search by phone" and "mobile phone" in customers addresses. But in this case with back office order search field i was looking the solution in wrong place in order files and not in customers. I was searching for function with a name something like searchcustomer and the function was searchByName!

Now i search the way to auto add a product reference number same with product ID while you save a new product.

I know how to copy the ID's in product reference field in SQL but i want this to be done automatically every time you save the product. Any idea?

Thanks you very much, you already save me a lot of time!



 

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...