Prestashop将地址列添加到客户后台

时间:2016-09-16 09:45:52

标签: php prestashop prestashop-1.6

我正在使用prestashop v 1.6.1.1

我想要的是什么

我正在尝试在后台添加一个名为dni的列到我的客户部分。

我尝试了什么

我知道要执行此操作的文件名为AdminCustomersController.php,它位于controllers / admin / AdminCustomersController.php

此外,我知道通过此查询,我可以获取数据库中的数据:

SELECT ps_address.dni, ps_customer. *
FROM ps_customer
INNER JOIN ps_address ON ps_customer.id_customer = ps_address.id_customer

LIMIT 0,30

客户部分中的当前查询是:

SELECT a.`id_customer`, `firstname`, `lastname`, `email`, a.`active` AS `active`, `newsletter`, `optin` , a.date_add, gl.name as title, ( SELECT SUM(total_paid_real / conversion_rate) FROM ps_orders o WHERE o.id_customer = a.id_customer AND o.id_shop IN (2, 1) AND o.valid = 1 ) as total_spent, ( SELECT c.date_add FROM ps_guest g LEFT JOIN ps_connections c ON c.id_guest = g.id_guest WHERE g.id_customer = a.id_customer ORDER BY c.date_add DESC LIMIT 1 ) as connect, shop.name as shop_name FROM `ps_customer` a LEFT JOIN ps_gender_lang gl ON (a.id_gender = gl.id_gender AND gl.id_lang = 1) LEFT JOIN ps_shop shop ON a.id_shop = shop.id_shop WHERE 1 AND a.`deleted` = 0 AND a.id_shop IN (2, 1) ORDER BY `date_add` DESC LIMIT 0, 50

我不知道

我不知道如何更改该查询以仅添加ps_address.dni并获取其他列。

由于

已编辑部分解决

好吧,最后我没有更改AdminCustomersController.php我更改了AdminAddressesController.php,这意味着更改客户/方向后台。

我刚添加了这些行,它就像魅力一样:

    $this->fields_list = array(
        'id_address' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
        'firstname' => array('title' => $this->l('First Name'), 'filter_key' => 'a!firstname'),
        'lastname' => array('title' => $this->l('Last Name'), 'filter_key' => 'a!lastname'),
        'address1' => array('title' => $this->l('Address')),
        'postcode' => array('title' => $this->l('Zip/Postal Code'), 'align' => 'right'),
        'dni' => array('title' => $this->l('DNI'), 'align' => 'right'),
        'city' => array('title' => $this->l('City')),
        'country' => array('title' => $this->l('Country'), 'type' => 'select', 'list' => $this->countries_array, 'filter_key' => 'cl!id_country'));

现在我可以搜索DNI-customer

2 个答案:

答案 0 :(得分:0)

试试这个,覆盖AdminCustomersController,名为prestashop/override/controllers/admin/的{​​{1}}中的新文件

AdminCustomersController.php

您无需做任何其他事情。但是,如果客户拥有更多的地址,则可能会产生意外结果。

答案 1 :(得分:-1)

您必须在AdminCustomersController.php文件夹中创建名为override/controllers/admin的新文件。请阅读this以获取更多信息。

然后,在__construct()函数中,您必须向$this->select附加一个子查询,并将相应的字段添加到$this->fields_list

此后是我在BO订单页面上添加发票ID的示例,该过程与您尝试实现的过程非常相似:

<?php 
class AdminOrdersController extends AdminOrdersControllerCore
{

public function __construct()
{
    parent::__construct();

    $this->_select .= '
        , (SELECT MAX(oi.id_order_invoice) FROM '._DB_PREFIX_.'order_invoice oi WHERE oi.id_order = a.id_order) as id_inv
    ';

    $this->fields_list = array_merge($this->fields_list, array(
        'id_inv' => array(
            'title' => $this->l('Invoice'),
            'align' => 'text-center',
            'class' => 'fixed-width-xs',
            'orderby' => false,
            'search' => false
        )
    ));
}
[...]
}