qqlaw
qqlaw

Reputation: 31

Prestashop - Backoffice - Add Order show address

When I am in backoffice and try to add an order and search for my customers I would like to show the customer's address in the little box. AddOrder-Search for Customer screenshot

in /themes/default/template/controllers/orders/form.tpl i have:

 function searchCustomers()
   {
..........................
            html += '<div class="panel-heading">'+this.company+' '+this.firstname+' '+this.lastname;
            html += '<span class="pull-right">#'+this.id_customer+'</span></div>';
            html += '<span>'+this.email+'</span><br/>';
            html += '<span>'+this.addresses+'</span><br/>';

But that just shows as "undefined" so i think i need to add something in the controllers/admin/AdminCustomersController.php (searchCustomers) but i am not sure.

Can somebody tell me what code am i missing?

I am using Prestashop 1.6.1.7

Upvotes: 2

Views: 440

Answers (1)

sadlyblue
sadlyblue

Reputation: 2987

To display the data, you need to get the data if it's not there. In this case, the this.addresses notifies undefined, because it doesn't "exist".

You can use this in override/controllers/admin/AdminCustomerControllers.php

public function ajaxProcessSearchCustomers()
    {
        $searches = explode(' ', Tools::getValue('customer_search'));
        $customers = array();
        $searches = array_unique($searches);
        foreach ($searches as $search) {
            if (!empty($search) && $results = Customer::searchByName($search, 50)) {
                foreach ($results as $result) {
                    if ($result['active']) {
                        $customer = new Customer($result['id_customer']);
                        $addresses = $customer->getAddresses($this->context->language->id);
                        $result['addresses'] = '';
                        if(is_array($addresses) and !empty($addresses))
                        {
                            foreach ($addresses as $address) {
                                $result['addresses'] .= $address['alias'].'<br />';
                            }
                        }
                        $customers[$result['id_customer']] = $result;
                    }
                }
            }
        }

        if (count($customers)) {
            $to_return = array(
                'customers' => $customers,
                'found' => true
            );
        } else {
            $to_return = array('found' => false);
        }

        $this->content = Tools::jsonEncode($to_return);
    }

This will define the addresses (only the aliases of the addresses, if you need more just change the line $result['addresses'] .= $address['alias'].'<br />';.

Don't forget to set the correct class class AdminCustomersController extends AdminCustomersControllerCore and then delete the file cache/class_index.php

Upvotes: 1

Related Questions