^ "SELECT p.id_product FROM (SELECT p.id_product, p.id_manufacturer, SUM(sa.quantity) as quantity, p.condition, p.weight, p.price, psales.quantity as sales, p.on_sale, p.date_add, cp.position FROM hb24_product p LEFT JOIN hb24_product_attribute pa ON (p.id_product = pa.id_product) LEFT JOIN hb24_product_attribute_combination pac ON (pa.id_product_attribute = pac.id_product_attribute) LEFT JOIN hb24_stock_available sa ON (p.id_product = sa.id_product AND IFNULL(pac.id_product_attribute, 0) = sa.id_product_attribute AND sa.id_shop = 1  AND sa.id_shop_group = 0 ) LEFT JOIN hb24_product_sale psales ON (psales.id_product = p.id_product) INNER JOIN hb24_category_product cp ON (p.id_product = cp.id_product) INNER JOIN hb24_product_shop ps ON (p.id_product = ps.id_product AND ps.id_shop = 1 AND ps.active = TRUE) INNER JOIN hb24_category c ON (cp.id_category = c.id_category AND c.active=1) LEFT JOIN hb24_category_group cg ON (cg.id_category = c.id_category) WHERE ps.id_shop='1' AND ps.visibility IN ('both', 'catalog') AND cg.id_group='1' AND p.id_manufacturer IN (94, 88, 106, 115, 143) AND cp.id_category IN (2, 110, 331, 112, 270, 272, 281, 273, 414, 415, 116, 434, 435, 316, 117, 119, 118, 398, 464, 471, 370, 128, 399, 374, 375, 416, 363, 130, 421, 422, 423, 424, 425, 432, 430, 401, 358, 359, 290, 361, 427, 402, 134, 149, 357, 133, 428, 429, 368, 366, 403, 365, 364, 367, 369, 137, 258, 259, 260, 431, 336, 463, 289, 132, 436, 135, 249, 444, 404, 153, 151, 154, 155, 443, 152, 156, 161, 405, 138, 136, 437, 164, 141, 351, 315, 350, 348, 454, 456, 314, 438, 439, 440, 441, 442, 445, 446, 447, 448, 449, 450, 376) GROUP BY p.id_product) p INNER JOIN hb24_category_product cp ON (p.id_product = cp.id_product) GROUP BY p.id_product ORDER BY p.quantity > 0 DESC, p.position ASC ASC, p.id_product DESC"