当我在后台,尝试添加订单并搜索我的客户时,我希望在小方框中显示客户的地址。AddOrder-Search for Customer screenshot
在/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/>';但这只是显示为“未定义的”,所以我认为我需要在controllers/admin/AdminCustomersController.php (searchCustomers)中添加一些东西,但我不确定。
谁能告诉我我漏掉了什么代码?
我使用的是Prestashop 1.6.1.7
发布于 2017-02-18 01:23:51
要显示数据,您需要在数据不存在的情况下获取数据。在这种情况下,this.addresses通知undefined,因为它不“存在”。
您可以在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);
}这将定义地址(仅定义地址的别名,如果需要更多,只需更改行$result['addresses'] .= $address['alias'].'<br />';。
不要忘记设置正确的类class AdminCustomersController extends AdminCustomersControllerCore,然后删除文件cache/class_index.php
https://stackoverflow.com/questions/42300702
复制相似问题