Voici enfin un caddie(panier) qui marche

Répondre
caporga
le 24/09/2007 à 13:48
caporga
<?php
session_start();
//init des variables
if (!isset($_SESSION['total'])) $_SESSION['total']=0;

?>
<?php require_once('ConnexionBoutiquemx.php'); ?>
<?php
mysql_select_db($database_ConnexionBoutiquemx, $ConnexionBoutiquemx);
//----------------------------------------------------AJOUT PANIER
if(!isset($_SESSION['panier'])){
$_SESSION['panier'] = array();
}

if ($_GET['action']=="AJOUTER"){

$index = array_key_exists($_GET['id_prod'], $_SESSION['panier']);
if($index==true){
$_SESSION['panier'][$_GET['id_prod']]++;
}
else
{
$_SESSION['panier'][$_GET['id_prod']] = 1;
}
//ajoute un article à la liste
}
//----------------------------------------------------VIDER PANIER
if ($_GET['action']=="VIDER"){
// permet de vider le panier
$_SESSION['panier'] = array();
}
//----------------------------------------------------SUPP PANIER
if($_GET['action']=="SUPPRIMER"){
unset($_SESSION['panier'][$_GET["id_prod"]]);
}
//----------------------------------------------------COMMANDER
if(isset($_POST)){

foreach($_POST as $id_form => $new_quant){
$expose_select_name = explode("_", $id_form);
if($expose_select_name!=false){
$_SESSION['panier'][$expose_select_name[1]] = $new_quant;
}
}
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- header -->
<div class="droitecentreheaderproduits" id="droitecentreheaderadmin">
<table width="100%" border="0" cellspacing="0">
<tr>
<td><p align="center">
<?php
if(sizeof($_SESSION['panier'])>0) {
?> </p>
<table width="771" align="center" cellspacing="0">
<tr>
<td width="767"><table width="781" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="19" colspan="2" valign="top"> <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Titre</font></strong></font></div></td>
<td width="63" valign="top"> <div align="center"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Quantit&eacute;</font></strong></font></div></td>
<td width="118" valign="top"><div align="center"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Pr</font></strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ix unitaire </strong></font></div></td>
<td width="118" valign="top"> <div align="center"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Prix</font></strong></font></div></td>
<td width="36" valign="top"> <div align="center"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Supp</font></strong></font></div></td>
</tr>
<?php
$total=0.00;
foreach($_SESSION['panier'] as $key => $value){

$query_rsPanier="SELECT * FROM articles_tbl WHERE id ='".$key."'"; //echo $query_rsPanier;
$rsPanier = mysql_query ($query_rsPanier, $ConnexionBoutiquemx) or die(mysql_error());
$row_rsPanier = mysql_fetch_assoc($rsPanier);
?>
<tr>
<td width="76" rowspan="2" align="center" valign="middle"><img src="../images_articles/<?php echo $row_rsPanier['photo']; ?>" width="45" height="45"/></td>
<td width="322" height="28" align="left" valign="bottom"><span class="soustitrebold"><?php echo $row_rsPanier['nom_produit'] ?></span></td>
<td rowspan="2" align="center" valign="middle"><div align="center">
<form action="panier.php" method="post" >
<select name="nb_<?=$key?>" onchange="this.form.submit();">
<? for($i_n=1; $i_n<=100; $i_n++){ ?>
<option value="<?=$i_n?>" <?php if($value==$i_n) echo "SELECTED"; ?>>x <?=$i_n?></option>
<? } ?>
</select>
</form>
</div></td>
<td rowspan="2" align="center" valign="middle"><span class="soustitreboldorange2"><?php echo $row_rsPanier['prix'] ?></span></td>
<td rowspan="2" align="center" valign="middle"><div align="center"><div class="soustitreboldorange2"><?php echo $row_rsPanier['prix']*$value ?> €</div>
</div></td>
<td rowspan="2"><div align="center"><a href="panier.php?action=SUPPRIMER&id_prod=<?php echo $row_rsPanier['id'] ?>"><img src="../images/supgif" width="20" height="20" border="0"></a></div></td>
</tr>
<tr>
<td width="322" height="28" align="left" valign="top"><div class="texte"><?php echo $row_rsPanier['quantite'] ?> - <?php echo $row_rsPanier['format'] ?> - <?php echo $row_rsPanier['grammage'] ?> - <?php echo $row_rsPanier['faconnage'] ?></div></td>
</tr>
<?php

$total+=$row_rsPanier['prix']*$value;
}
$_SESSION['total']=$total;//mAj du total dans la session

?>
<tr>
<td colspan="2" ><div align="center"></div></td>
<td ><div align="center"></div></td>
<td >&nbsp;</td>
<td ><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Total
: <?php echo $total ?> Euros</strong></font></div></td>
<td ><div align="center"></div></td>
</tr>
</table></td>
</tr>
</table>
<br>
<p align="center">
<input type="submit" name="enregistreCommande" value="COMMANDER" onclick="window.location.href='commande.php'">


</p>
<?php
}
else
{
?>
<p align="center"><strong><font size="4" face="Verdana, Arial, Helvetica, sans-serif">Votre panier est vide</font></strong></p>
<?php
}
?>
</td>
</tr>
</table>
</div>
<!-- //header -->
caporga
Répondre

Ecrire un message

Votre message vient d'être créé avec succès.
LoadingChargement en cours