【问题标题】:Prestashop - Backoffice - Add Order show addressPrestashop - 后台 - 添加订单显示地址
【发布时间】:2017-02-17 14:44:21
【问题描述】:

当我在后台并尝试添加订单并搜索我的客户时,我想在小框中显示客户的地址。 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/>';

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

谁能告诉我我缺少什么代码?

我正在使用 Prestashop 1.6.1.7

【问题讨论】:

    标签: php prestashop customization


    【解决方案1】:

    要显示数据,如果数据不存在,您需要获取数据。在这种情况下,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'].'&lt;br /&gt;'; 行。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-07
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2017-01-05
      • 2012-12-01
      • 2015-01-14
      • 1970-01-01
      相关资源
      最近更新 更多