You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND p.active = 1 ORDER BY cp.position ASC LIMIT 1' at line 7

                SELECT p.id_product, l.link_rewrite
                FROM `ps_product` p
                LEFT JOIN `ps_product_lang` l
                    ON l.`id_product` = p.`id_product`
		LEFT JOIN `ps_category_product` cp 
                    ON (p.`id_product` = cp.`id_product`)
                WHERE id_category =  AND p.active = 1
                ORDER BY cp.position ASC LIMIT 1