将公司字段添加到BackOffice中的“客户”选项卡

时间:2012-10-09 07:52:19

标签: php mysql prestashop

我正在运行prestashop 1.4.8.3并且我在AdminCustomers.php上尝试了以下修改

     $this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5)<RIGHT(`birthday`, 5)) as age, (
            SELECT c.date_add FROM ' . _DB_PREFIX_ . 'guest g
            LEFT JOIN ' . _DB_PREFIX_ . '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';

// This is new code
$this->_select = '(SELECT d.company FROM ' . _DB_PREFIX_ . 'address d WHERE d.id_customer = a.id_customer LIMIT 1) as company';

// LH company name
$genders = array(
    1 => $this->l('M'),
    2 => $this->l('F'),
    9 => $this->l('?'));
$this->fieldsDisplay = array(
    'id_customer' => array(
        'title' => $this->l('ID'),
        'align' => 'center',
        'width' => 25),
    'id_gender' => array(
        'title' => $this->l('Gender'),
        'width' => 25,
        'align' => 'center',
        'icon' => array(
            1 => 'male.gif',
            2 => 'female.gif',
            'default' => 'unknown.gif'),
        'orderby' => false,
        'type' => 'select',
        'select' => $genders,
        'filter_key' => 'a!id_gender'),
    'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
    'firstname' => array('title' => $this->l('First name'), 'width' => 60),
    'email' => array(
        'title' => $this->l('E-mail address'),
        'width' => 120,
        'maxlength' => 19),
    'company' => array('title' => $this->l('Company'), 'width' => 60),
    'age' => array(
        'title' => $this->l('Age'),
        'width' => 30,
        'search' => false),
    'active' => array(
        'title' => $this->l('Enabled'),
        'width' => 25,
        'align' => 'center',
        'active' => 'status',
        'type' => 'bool',
        'orderby' => false),
    'newsletter' => array(
        'title' => $this->l('News.'),
        'width' => 25,
        'align' => 'center',
        'type' => 'bool',
        'callback' => 'printNewsIcon',
        'orderby' => false),
    'optin' => array(
        'title' => $this->l('Opt.'),
        'width' => 25,
        'align' => 'center',
        'type' => 'bool',
        'callback' => 'printOptinIcon',
        'orderby' => false),
    'date_add' => array(
        'title' => $this->l('Registration'),
        'width' => 30,
        'type' => 'date',
        'align' => 'right'),
    'connect' => array(
        'title' => $this->l('Connection'),
        'width' => 60,
        'type' => 'datetime',
        'search' => false));

奇怪的是它似乎工作,但只有一两个浏览器刷新,之后它无法显示SQL失败消息。

任何能让我走上正轨的想法都会受到高度赞赏。

2 个答案:

答案 0 :(得分:0)

您可以尝试一下:

// This is new code
$this->_select .= ', (SELECT d.company FROM ' . _DB_PREFIX_ . 'address d WHERE d.id_customer = a.id_customer LIMIT 1) as company';

你也可以在这里看到你的sql-query: 第AdminTab::getList()行<{1}}

答案 1 :(得分:0)

在打开的文件config&gt;上尝试show sql debug config.inc.php并设置为true define('_PS_DEBUG_SQL_', false)。您会注意到错误语法sql。 不要忘记尝试修改代码

  

$ temp ='(SELECT d.company FROM'._DB_PREFIX_。'address d WHERE   d.id_customer = a.id_customer LIMIT 1)作为公司';

     

的var_dump(DB ::的getInstance() - &GT;执行($ SQL));

最后,运行你的代码,你会发现错误:)