2016-12-05 111 views
0

我想在Prestashop 1.6上为我的模块创建一个自定义列表,我需要从三个不同的表中获取数据。我的问题是$this->_filter变量,我该怎么做?在我的模块上筛选Prestashop 1.6

我需要这样做:

$query = ' 
SELECT s.*, pl.* 
FROM '._DB_PREFIX_.'`scd_gift` s 
INNER JOIN '._DB_PREFIX_.'product_lang pl 
ON s.id_product = pl.id_product 
WHERE s.`id_gift_type` = '.(int)$id_gift_type.' and id_lang='.$id_lang; 

这里是我的功能:

public function getCustomListHostessGifts() { 
    $this->table = 'scd_gift'; 
    $this->list_id = 'hostess_gift'; 
    $this->lang = true; 
    $this->identifier = 'id_scd_gift'; 
    $this->_orderBy = 'id_product'; 
    $this->_orderWay = 'DESC'; 

    $this->addRowAction('delete'); 

    $this->fields_list = (array(
     'id_product' => array('title' => $this->l('ID'), 'class' => 'fixed-width-xs', 
           'align' => 'center'), 
     'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'), 
    )); 

    $this->clearFilters(); 

    $hostessType = MlmGiftsModule::getGiftTypeIdByGiftTypeName('_HOSTESSGIFT_'); 

    $this->_join = Shop::addSqlAssociation('scd_gift', 'a'); 

    $this->_filter = ' 
     INNER JOIN '._DB_PREFIX_.'product_lang pl 
       ON s.id_product = pl.id_product 
       AND a.`id_gift_type` ='.$hostessType ; 

    $this->toolbar_title = $this->l('Hostess gifts:'); 

    return $this->renderList(); 
} 

回答

0

_filter是利用设置在后台列表搜索字段通过滤波器参数。 任何JOIN句子必须_join VAR进行设置:

$this->_join = Shop::addSqlAssociation('scd_gift', 'a'); 
     . ' INNER JOIN '._DB_PREFIX_.'product_lang pl 
       ON s.id_product = pl.id_product 
       AND a.`id_gift_type` ='.$hostessType ; 

好运。

0

PixelWeb的答案是正确的,但当然,还有后

$this->_join = Shop::addSqlAssociation('scd_gift', 'a') 

其他别无分号。无论如何,你可以跳过这一行,因为Prestashop为控制器本身的表添加了默认的SQL关联“a”。