Pour la réparation
et un service de qualité


Porte de garage, New DOMUSTAR S500R | SAV-Motostar

SELECT p.*, pd.*, pq.prix as prix_defaut, IF(pd.ref <> '', pd.ref, p.ref) as ref, MIN(IF(pd.prix_promo<>0, pd.prix_promo, IF(c3.promo_pourc<>0 AND c3.promo_date_debut <= CURRENT_DATE() AND c3.promo_date_fin >= CURRENT_DATE(), ROUND(IF(pd.prix<>0, pd.prix, pq.prix) - (IF(pd.prix<>0, pd.prix, pq.prix)*(c3.promo_pourc/100)), 2), IF(c2.promo_pourc<>0 AND c2.promo_date_debut <= CURRENT_DATE() AND c2.promo_date_fin >= CURRENT_DATE(), ROUND(IF(pd.prix<>0, pd.prix, pq.prix) - (IF(pd.prix<>0, pd.prix, pq.prix)*(c2.promo_pourc/100)), 2), IF(c1.promo_pourc<>0 AND c1.promo_date_debut <= CURRENT_DATE() AND c1.promo_date_fin >= CURRENT_DATE(), ROUND(IF(pd.prix<>0, pd.prix, pq.prix) - (IF(pd.prix<>0, pd.prix, pq.prix)*(c1.promo_pourc/100)), 2), IF(pd.prix<>0, pd.prix, IF(pq.prix_promo<>0, pq.prix_promo, pq.prix))))))) as prix_final, MAX(IF(pd.prix_promo<>0, 1, IF(c3.promo_pourc<>0 AND c3.promo_date_debut <= CURRENT_DATE() AND c3.promo_date_fin >= CURRENT_DATE(),1,IF(c2.promo_pourc<>0 AND c2.promo_date_debut <= CURRENT_DATE() AND c2.promo_date_fin >= CURRENT_DATE(),1,IF(c1.promo_pourc<>0 AND c1.promo_date_debut <= CURRENT_DATE() AND c1.promo_date_fin >= CURRENT_DATE(),1,IF(pd.prix=0 AND pq.prix_promo<>0, 1, 0)))))) as en_promo, IF(pd.prix_promo<>0, 1, IF(c3.promo_pourc<>0 AND c3.promo_date_debut <= CURRENT_DATE() AND c3.promo_date_fin >= CURRENT_DATE(),1,IF(c2.promo_pourc<>0 AND c2.promo_date_debut <= CURRENT_DATE() AND c2.promo_date_fin >= CURRENT_DATE(),1,IF(c1.promo_pourc<>0 AND c1.promo_date_debut <= CURRENT_DATE() AND c1.promo_date_fin >= CURRENT_DATE(),1,IF(pd.prix=0 AND pq.prix_promo<>0, 1, 0))))) as promotion, c3.id_cat as id_cat3, c3.nom_cat as cat3, c2.id_cat as id_cat2, c2.nom_cat as cat2, c1.id_cat as id_cat1, c1.nom_cat as cat1, t.* FROM produits p INNER JOIN tva t ON p.rid_tva = t.id_tva INNER JOIN categories c3 ON p.rid_cat = c3.id_cat AND c3.afficher = '1' LEFT OUTER JOIN categories c2 ON c3.rid_cat = c2.id_cat AND c2.afficher = '1' LEFT OUTER JOIN categories c1 ON c2.rid_cat = c1.id_cat AND c1.afficher = '1' INNER JOIN produits__decli pd ON p.id_prod = pd.rid_prod INNER JOIN produits__qte pq ON p.id_prod = pq.rid_prod AND pq.qte = '1' WHERE p.afficher='1' AND pd.afficher = '1' AND (p.rid_cat = '29' OR p.rid_cat2 = '29' OR p.rid_cat3 = '29' OR c2.id_cat = '29' OR c1.id_cat = '29') GROUP BY id_prod HAVING prix_final > '0' ORDER BY prix_final, nom