SELECT c0_.product_id AS sclr_0 FROM category_product c0_ INNER JOIN product p1_ ON c0_.product_id = p1_.product_id WHERE c0_.category_id = ? AND p1_.show_online = 1 AND p1_.consecutive_days_out_of_stock < ? ORDER BY p1_.in_stock DESC, p1_.has_image DESC, p1_.sort_score DESC