2017-02-17 35 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

相關問題