2016-12-04 43 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