2017-02-17 110 views
2

当我在后台并尝试添加订单并搜索我的客户时,我想在小方框中显示客户的地址。 AddOrder-Search for Customer screenshotPrestashop - 后台 - 添加订单显示地址

在/themes/default/template/controllers/orders/form.tpl我有:

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/>'; 

但是,这只是显示为“未定义” ,所以我想我需要在添加的东西控制器/管理员/ AdminCustomersController.php(searchCustomers),但我不知道。

有人可以告诉我我错过了什么代码吗?

我使用的Prestashop 1.6.1.7

回答

1

要显示的数据,你需要获取的数据,如果它不存在。在这种情况下,this.addresses通知未定义,因为它不存在。

您可以覆盖/控制器/管理员使用/ 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); 
    } 

这将定义地址(只有地址的别名,如果你需要更多的只是更改线路$result['addresses'] .= $address['alias'].'<br />';

不要忘了设置正确的类class AdminCustomersController extends AdminCustomersControllerCore,然后删除文件cache/class_index.php

+0

谢谢!完美的作品! – qqlaw

相关问题