Created
March 27, 2015 09:26
-
-
Save mistergraphx/f0c7205aec6e906f4a4e to your computer and use it in GitHub Desktop.
Après commande : exemple de traitement effectué après le passage d'une commande au statut
<http://contrib.spip.net/Commandes-4527>
et plus spécialement : <http://contrib.spip.net/Commandes-4527#forum478302>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Changer les quantités des objets d'une commande quand elle passe du statut "attente" à "paye" | |
function ed_com_post_edition($flux){ | |
if ( | |
$flux['args']['action'] == 'instituer' | |
AND $flux['args']['table'] == 'spip_commandes' | |
AND ($id_commande = intval($flux['args']['id_objet'])) > 0 | |
AND ($statut_nouveau = $flux['data']['statut']) == 'paye' | |
AND ($statut_ancien = $flux['args']['statut_ancien']) == 'attente' | |
){ | |
// retrouver les objets correspondants à la commande dans spip_commandes_details | |
if ( | |
$objets = sql_allfetsel('objet,id_objet,quantite', 'spip_commandes_details', 'id_commande='.intval($id_commande)) | |
AND is_array($objets) | |
AND count($objets) | |
){ | |
// mettre à jour la quantité de chaque objet de la commande | |
include_spip('action/editer_objet'); | |
foreach($objets as $v) { | |
// récupérer les infos | |
$objet = $v['objet']; // 'article' | |
$id_table_objet = id_table_objet($objet); // 'id_article' | |
$table_objet = table_objet_sql($objet); // 'spip_articles' | |
$id_objet = intval($v['id_objet']); | |
$quantite = intval($v['quantite']); | |
// calculer la nouvelle quantité | |
$quantite_ancienne = intval(sql_getfetsel('quantite', $table_objet, $id_table_objet.'='.$id_objet)); | |
$quantite_nouvelle = $quantite_ancienne - $quantite; | |
// mettre à jour la quantité | |
if ($quantite_nouvelle) > 0 { | |
objet_modifier($objet, $id_objet, array('quantite'=>$quantite_nouvelle)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment