Bonjour voila je vous explique j'ai créer un panier pour un site web.J'utilise les sessions pour enregistrer les articles avec la référence et la quantité ainsi que le prix meme si celui la je peux le récupérer dans ma base de données. Ce que je souhaite c'est pouvoir afficher le contenu de mon panier sous forme de tableau. J'ai essayé de faire une boucle foreach pour parcourir la session mais je n'y arrive pas et j'ai abandonné voici mon code:
Modifié par greg12 (15 Sep 2008 - 11:44)
session_start();
$prixtotal=0; //initialise prix total d'un panier
//test si la session existe
if(!isset($_SESSION['panier']))
$_SESSION['panier']=array();
//verification du click sur le bouton ajouter
if(isset($_POST['ajouter']))
{
if($_POST['ref']==$_SESSION['panier']['article_'.$_POST['ref']]['ref'])
{
$_SESSION['panier']['article_'.$_POST['ref']]['ref']=$_POST['ref'];
$_SESSION['panier']['article_'.$_POST['ref']]['qte']=$_SESSION['panier']['article_'.$_POST['ref']]['qte']+$_POST['quantite'];
$_SESSION['panier']['article_'.$_POST['ref']]['prix']=$_POST['prix'];
$_SESSION['panier']['prixtotal']=$_SESSION['panier']['prixtotal']+($_POST['quantite']*$_POST['prix']);
$_SESSION['panier']['nb']=$_SESSION['panier']['nb']+($_POST['quantite']);
}else{
$_SESSION['panier']['article_'.$_POST['ref']]=array();
$_SESSION['panier']['article_'.$_POST['ref']]['ref']=$_POST['ref'];
$_SESSION['panier']['article_'.$_POST['ref']]['qte']=$_POST['quantite'];
$_SESSION['panier']['article_'.$_POST['ref']]['prix']=$_POST['prix'];
$_SESSION['panier']['prixtotal']=$_SESSION['panier']['prixtotal']+($_POST['quantite']*$_POST['prix']);
$_SESSION['panier']['nb']=$_SESSION['panier']['nb']+($_POST['quantite']);
}
/*$ref=$_POST['ref'];//recupere identifiant du produit
header("location: http://localhost/elleon/shop/produits.php?id=$ref");//renvoi vers la page produit*/
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
Modifié par greg12 (15 Sep 2008 - 11:44)