1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<?php
//récupérer le derniernuméro de commande attribué au client actuel
if (isset($_SESSION['MM_Username'])) {
mysql_select_db($database_xxx, $xxx);
$query_commande = sprintf("SELECT id
FROM commande
WHERE mail ='".$_SESSION['MM_Username']."'
ORDER BY id DESC");
$commande = mysql_query($query_commande, $xxx) or die(mysql_error());
$row_commande = mysql_fetch_assoc($commande);
$totalRows_commande = mysql_num_rows($commande);
//récupérer la 1ere ligne du panier
mysql_select_db($database_xxx, $xxx);
$query_panier = sprintf("SELECT panier.*,
produit.prix,
produit.prix*panier.quantite
AS ss_total_ttc,
produit.prix*panier.quantite/1.196
AS ss_total_ht
FROM panier
INNER JOIN produit
ON produit.id=panier.produit
WHERE panier.client = '".$_SESSION['MM_Username']."'");
$panier = mysql_query($query_panier, $xxx) or die(mysql_error());
//nombre d'enregistrements total concerné par la requete et initialisation compteur (retient le nb de lignes deja traitees et stoppe le processus si tt le panier a ette converti)
$totalRows_panier = mysql_num_rows($panier);
$compteur = 0;
// boucle de conversion
while ($row_panier = mysql_fetch_assoc($panier) and $compteur < $totalRows_panier)
{
$query_ligne_commande = sprintf("INSERT
INTO ligne_commande (commande, produit, prix, quantite, ss_total_ht, ss_total_ttc) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($row_commande['id'], "int"),
GetSQLValueString($row_panier['produit'], "int"),
GetSQLValueString($row_panier['prix'], "double"),
GetSQLValueString($row_panier['quantite'], "int"),
GetSQLValueString($row_panier['ss_total_ht'], "double"),
GetSQLValueString($row_panier['ss_total_ttc'], "double"));
mysql_select_db($database_xxx, $xxx);
$Resultat1 = mysql_query($query_ligne_commande, $xxx) or die(mysql_error());
$query_suppr_panier = sprintf("DELETE FROM panier WHERE id=%s",
GetSQLValueString($row_panier['id'], "int"));
mysql_select_db($database_xxx, $xxx);
$Resultat1 = mysql_query($query_suppr_panier, $xxx) or die(mysql_error());
$compteur = $compteur+1;
}
}
?> |
Partager