Prestashop Admin选项卡 - clausole不起作用的地方

时间:2013-06-01 13:34:38

标签: php mysql prestashop

我正在为prestashop编写一个Tab,列出了原产国的客户。 到目前为止它没关系,但我想逐个过滤查询或表格,所以我想添加如下内容: 在哪里iso_code ='IT' 显然prestashop不会让我,我该怎么办? 这是我的代码:

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCustomersCountries extends AdminTab
{
    public function __construct()
    {
        $this->table = 'customer';
        $this->className = 'Customer';
        $this->lang = false;
        $this->edit = false;
        $this->view = true;
        $this->delete = false;
        $this->deleted = false;
        $this->requiredDatabase = true;

        $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country) AS iso_code';
        $this->fieldsDisplay = array(
        'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
        '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),
        '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),
        'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false));

        $this->optionTitle = "Prova";
        parent::__construct();
    }

    public function postProcess()
    {
        // This function is executed when the Submit button is clicked
        // Use it to store the value of text fields in the database

        parent::postProcess();
    }

    public function displayForm($token=NULL)
    {
        // This function can be used to create a form with text fields
    }
}

?>

但是,我尝试添加WHERE子句,但没有结果:

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCustomersCountries extends AdminTab
{
    public function __construct()
    {
        $this->table = 'customer';
        $this->className = 'Customer';
        $this->lang = false;
        $this->edit = false;
        $this->view = true;
        $this->delete = false;
        $this->deleted = false;
        $this->requiredDatabase = true;

        $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code='IT') AS iso_code';
        $this->fieldsDisplay = array(
        'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
        '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),
        '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),
        'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false));

        $this->optionTitle = "Prova";
        parent::__construct();
    }

    public function postProcess()
    {
        // This function is executed when the Submit button is clicked
        // Use it to store the value of text fields in the database

        parent::postProcess();
    }

    public function displayForm($token=NULL)
    {
        // This function can be used to create a form with text fields
    }
}

?>

2 个答案:

答案 0 :(得分:1)

我不确定你为什么在那里使用子查询,但PS AdminTab类提供了另外两个选项。

1)其中:每当你需要一个add where子句时,你可以像下面那样写出

$this->_where = 'your condition here';

2)加入:PS还为您提供了额外的连接功能,您可以像

一样编写它们
$this->_join = 'write down all your joins here like normal queries';

现在,如果你想从其他表中获得额外的信息并附加检查(wheres),那么你可以按照以下方式进行操作。 :

**注意:对于表,PS给别名以“a”开头,如果它有其他表格,如语言表,那么它与b一起使用,依此类推。所以你应该知道,在join,_select和_where中你应该使用正确的别名。 **

$this->_select = 'all your additional fields from the tables you need. Those tables should be joined in the _join query.';

$this->_join = 'All your joins here with correct aliases, as these aliases are used in _select query and in _where';

$this->_where = 'your where clauses here.';

我希望这可以帮助您更正查询。

谢谢

答案 1 :(得分:0)

$this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code='IT') AS iso_code';行使用'IT'搜索IT。

PHP不会读取IT,因为撇号不会被转义。我认为使用AND cy.iso_code=\'IT\')应该有用。