jdepluvie Posted February 8, 2013 Share Posted February 8, 2013 Bonjour, j'ai un groupe de client qui dispose de tarifs négociés. en parralèlle j'ia un programme de fidélité (natif prestashop). Je ne souhaite pas que ceux qui disposent d'un tarif négocié puissent utiliser les points fidélités en bons de rédcution, le cumul des deux me ferait perdre de l'argent. aussi j'ai pensé à mettre une annulation des points fidélités dans un cas supplémentaire au moment de la facturation. j'ai d'abord rajouté un statut supplémentaire dans la table loyalty, et je bloque maintenant sur la requete qui ne passe pas : condition = appartenir au groupe de client numéro 2 UPDATE loyalty SET L.id_loyalty_state =6, L.points =0 FROM orders O, loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND O.`id_customer` = L.`id_customer` AND CG.id_group=2 AND CG.id_points !=0; quelqu'un a t il déjà eu cette reflexion ? et voyez vous l'erreur sur ma requete ? ne serait ce pass une chose à implémenter dasns le prgramme de fidélité : l'affecter à un groupe de client en amont pour ne pas avoir ce genre de souci ? Link to comment Share on other sites More sharing options...
jdepluvie Posted February 14, 2013 Author Share Posted February 14, 2013 j'ai diminué la requete select qui donne le bon résultat : SELECT L.`id_order`, L.id_loyalty_state, L.`points` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0; cependant je ne parviens pas a faire celle qui sert à l'update et mettre le points = 0 et id_loyalty_state = 6. l'un d'enrte vous aurait il une idée ? Merci Link to comment Share on other sites More sharing options...
Christophe Boix Posted February 14, 2013 Share Posted February 14, 2013 Bonjour, une requete d'update s'arrete là : update loyalty L set points=0 where id_loyalty_state =6 and L.id_customer = X il n'y a pas de FROM orders etc.. il faudrait par contre récupérer l' id_customer ( si vous êtes dans un foreach, vous aurez surement un $order['id_customer'] ) et placer cet update au bon endroit. $update='update loyalty L set points=0 where id_loyalty_state =6 and L.id_customer = '.(int)$order['id_customer']; Link to comment Share on other sites More sharing options...
jdepluvie Posted February 14, 2013 Author Share Posted February 14, 2013 Merci, non c'est une requete qui sera appelée en tache cron, je dois donc la faire "comme ca". on peut imbriquer des requetes il me semble Link to comment Share on other sites More sharing options...
Christophe Boix Posted February 14, 2013 Share Posted February 14, 2013 il ya une erreur sql, ou c'est plutot aucun résultat ? Dans la requete select, il y a CG.id_group=3, et dans la requete update , il y a CG.id_group=2, est-ce normal? Merci, non c'est une requete qui sera appelée en tache cron, je dois donc la faire "comme ca". on peut imbriquer des requetes il me semble oui on peut Link to comment Share on other sites More sharing options...
jdepluvie Posted February 14, 2013 Author Share Posted February 14, 2013 c'est une erreur en recopiant... je vais faire un test en imbriquant et posterait le résultat Link to comment Share on other sites More sharing options...
Christophe Boix Posted February 14, 2013 Share Posted February 14, 2013 (edited) Si le select fonctionne, alors peut etre que cette requete fonctionnera : update loyalty L set points=0 where id_loyalty_state =6 and L.id_customer in( SELECT CG.`id_customer` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0 ) ou update loyalty L set points=0 where id_loyalty_state =6 and L.id_customer in( SELECT L.`id_customer` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0 ) Edited February 14, 2013 by Christophe Boix (see edit history) Link to comment Share on other sites More sharing options...
jdepluvie Posted February 14, 2013 Author Share Posted February 14, 2013 Merci ! ca ca marche SELECT L.`id_order` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0; mais pas ca : UPDATE loyalty L SET points=0 WHERE id_loyalty_state =6 AND L.id_order IN( SELECT L.`id_order` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0 ); Error Code: 1093 // You can't specify target table 'L' for update in FROM clause UPDATE loyalty SET loyalty.`points`=0 WHERE id_loyalty_state =6 AND loyalty.id_order IN( SELECT loyalty.`id_order` FROM loyalty, customer_group WHERE loyalty.id_customer = customer_group.`id_customer` AND customer_group.id_group=3 AND loyalty.points !=0 ); You can't specify target table 'loyalty' for update in FROM clause Bizarre quand même Link to comment Share on other sites More sharing options...
Christophe Boix Posted February 14, 2013 Share Posted February 14, 2013 Essayez ça : UPDATE loyalty SET points=0 WHERE id_loyalty_state =6 AND id_order IN( SELECT L.`id_order` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0 ); Link to comment Share on other sites More sharing options...
Christophe Boix Posted February 14, 2013 Share Posted February 14, 2013 Ou sinon ce genre de requete peut être pas mal : $select='SELECT L.`id_order` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0' ...... foreach($result as $row){ .. UPDATE loyalty L SET points=0 WHERE id_loyalty_state =6 AND L.id_order=$row['id_order']; .. } Link to comment Share on other sites More sharing options...
jdepluvie Posted February 14, 2013 Author Share Posted February 14, 2013 (edited) post de 5:02 : même erreur 1093 pour votre post de 5:05, je suis incapable de la mettre en place Edited February 14, 2013 by jdepluvie (see edit history) Link to comment Share on other sites More sharing options...
Christophe Boix Posted February 14, 2013 Share Posted February 14, 2013 ok j'ai voulu faire vite, voici la bonne syntaxe des requetes pour le fichier qui sera en tache cron : $select='SELECT L.`id_order` FROM loyalty L, customer_group CG WHERE L.id_customer = CG.`id_customer` AND CG.id_group=3 AND L.points !=0'; $result=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($select); foreach($result as $row){ $update='UPDATE loyalty L SET points=0 WHERE id_loyalty_state =6 AND L.id_order='.$row['id_order']; Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($update); } Une variable $select qui permet de stocker tous les "id_order" Une variable $update qui va stocker la commande Sql qui sera executée grâce au Db::getInstance->executeS Est-ce que c'est mieux expliqué? Link to comment Share on other sites More sharing options...
jdepluvie Posted February 14, 2013 Author Share Posted February 14, 2013 oui c'et sbien expliqué ! je vais tenter ma chance avec ca? Merci !!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now