2016-12-04 54 views
0

我與PrestaShop內此查詢strugling,我知道它可以通過改變sa.available_for_order很容易解決,但這種方式它打破的其他核心文件的邏輯, 還有沒有其他的周圍的方式解決這一問題,而不重命名available_for_ordersa.available_for_order列「available_for_order」在where子句是曖昧

SELECT 
    a.`id_product`, 
    b.`name` AS `name`, 
    `reference`, 
    a.`price` AS `price`, 
    sa.`active` AS `active`, 
    `newfield`, 
    shop.`name` AS `shopname`, 
    a.`id_shop_default`, 
    image_shop.`id_image` AS `id_image`, 
    cl.`name` AS `name_category`, 
    sa.`price`, 
    0 AS `price_final`, 
    a.`is_virtual`, 
    pd.`nb_downloadable`, 
    sav.`quantity` AS `sav_quantity`, 
    sa.`active`, 
    IF(sav.`quantity` <= 0, 1, 0) AS `badge_danger`, 
    sa.`available_for_order` AS `available_for_order` 
FROM 
    `ps_product` a 
LEFT JOIN 
    `ps_product_lang` b 
ON 
    (
    b.`id_product` = a.`id_product` AND b.`id_lang` = 1 AND b.`id_shop` = 1 
) 
LEFT JOIN 
    `ps_stock_available` sav 
ON 
    (
    sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0 AND sav.id_shop = 1 AND sav.id_shop_group = 0 
) 
JOIN 
    `ps_product_shop` sa 
ON 
    (
    a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default 
) 
LEFT JOIN 
    `ps_category_lang` cl 
ON 
    (
    sa.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default 
) 
LEFT JOIN 
    `ps_shop` shop 
ON 
    (
    shop.id_shop = a.id_shop_default 
) 
LEFT JOIN 
    `ps_image_shop` image_shop 
ON 
    (
    image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = a.id_shop_default 
) 
LEFT JOIN 
    `ps_image` i 
ON 
    (
    i.`id_image` = image_shop.`id_image` 
) 
LEFT JOIN 
    `ps_product_download` pd 
ON 
    (pd.`id_product` = a.`id_product`) 
WHERE 
    1 AND `available_for_order` = 1 
ORDER BY 
    a.`id_product` ASC 
LIMIT 0, 50 

的Prestashop

 public function __construct() 
     { 
      parent::__construct(); 
    $this->_select .= ',sa.`available_for_order` AS `available_for_order`, '; 
      $this->fields_list['sa!available_for_order'] = array(
       'title' => $this->l('Available for order'), 
       'width' => 90, 
       'active' => 'available_for_order', 
       'filter_key' => 'sa!available_for_order', 
       'type' => 'bool', 
       'align' => 'center', 
       'orderby' => false 
      ); 
} 
+0

通過管理控制器中的renderList()生成查詢嗎? – TheDrot

+0

是我ovveride adminController 我更新了主方法線程與overide,謝謝 – user3606010

回答

0

修改你的領域列出使用具有過濾器。

$this->fields_list['available_for_order'] = array(
      'title' => $this->l('Available for order'), 
      'width' => 90, 
      'active' => 'available_for_order', 
      'filter_key' => 'available_for_order', 
      'havingFilter' => true, 
      'type' => 'bool', 
      'align' => 'center', 
      'orderby' => false 
     ); 

這將使用HAVING代替WHERE查詢。

WHERE子句對列別名不起作用,但HAVING不起作用。

+0

先生,謝謝你,很多很多 – user3606010

0

available_for_order必須在表的不止一個。只是限定列名,因爲你在做select

WHERE 1 AND sa.available_for_order = 1 
------------^ 
+0

對不起,但我需要它是'available_for_order'不'sa.available_for_order'如標題中所指定的,如果我把它放在SA。它刪除切換並顯示值爲0/1 無論如何,謝謝你的回答 – user3606010