Suppression article dans panier virtuel

johnjohn -  
Zep3k!GnO Messages postés 2025 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

J'ai crée un panier virtuel pour un site de vente en ligne.

Tout fonctionne correctement sauf lorsque j'ai plusieurs article dans le panier et que je veux supprimer le premier article il me supprime le dernier rajouter.

Voici le code de la page

$action = (isset($_POST['action'])? $_POST['action']: null ) ;
$option = (isset($_POST['option'])? $_POST['option']:null ) ;
$l = (isset($_POST['l'])? str_replace('&sp;',' ',$_POST['l']): null);
$id = (isset($_POST['id'])? $_POST['id']: null);
$q = (isset($_POST['q'])? $_POST['q']: null);
$photo = (isset($_POST['photo'])? $_POST['photo']: null);
$p = (isset($_POST['p'])? $_POST['p']: null);
$lien = (isset($_POST['lien'])? $_POST['lien']: null);

include_once("fonctions-panier.php");
$erreur = false;

if($action !== null) {
   if(!in_array($action,array('ajout', 'suppression', 'refresh')))
   $erreur=true;

 //Suppression des espaces verticaux
   $l = preg_replace('#\v#', '',$l);
   //On verifie que $p soit un float
   $p = floatval($p);

   //On traite $q qui peut etre un entier simple ou un tableau d'entier
    
   if (is_array($q)){
      $QteArticle = array();
      $i=0;
      foreach ($q as $contenu){
         $QteArticle[$i++] = intval($contenu);
      }
   }
   else
   $q = intval($q);
    
}
if (!$erreur){
   switch($action){
      Case "ajout":
         ajouterArticle($photo,$l,$option,$q,$p);
         break;

      Case "suppression":
         supprimerArticle($l);
         break;

      Case "refresh" :
         for ($i = 0 ; $i < count($QteArticle) ; $i++)
         {
            modifierQTeArticle($_SESSION['panier']['libelleProduit'][$i],round($QteArticle[$i]));
         }
         break;

      Default:
         break;
   }
}

echo '<?xml version="1.0" encoding="utf-8"?>';

?>

Et voila le panier

<h1 class="page">&nbsp;Mon Panier</h1>
<form method="post" action="Panier.php">
<table>
	<tr class="tb">
		<td class="L" colspan="3">Libellé</td>
		<td class="p">Quantité</td>
		<td class="o">Prix Unitaire</td>
		<td class="o">Prix Total</td>
		<td class="o">Supprimer</td>
	</tr>

	<?php

	if (creationPanier())
	{
	   $nbArticles=count($_SESSION['panier']['libelleProduit']);
	   if ($nbArticles <= 0)
	   echo "<tr><td>Votre panier est vide </ td></tr>";
	   else
	   {
	      for ($i=0 ;$i < $nbArticles ; $i++)
	      {
	         echo 	"<tr>
						<td><img src='".htmlspecialchars($_SESSION['panier']['photoProduit'][$i])."'/></td>
						<td>".htmlspecialchars($_SESSION['panier']['libelleProduit'][$i])."</ td>
						<td>".htmlspecialchars($_SESSION['panier']['option'][$i])."</td>
						<td class='p'><input type=\"text\" size=\"2\" name=\"q[]\" value=\"".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])."\"/></td>
						<td class='o'>".number_format(htmlspecialchars($_SESSION['panier']['prixProduit'][$i]),2,',','')."€</td>
						<td class='o'>".number_format($total=$_SESSION['panier']['qteProduit'][$i]*$_SESSION['panier']['prixProduit'][$i],2,',','')."€</td>
						<td class='X'>
						<input type=\"hidden\" name=\"l\" value='".str_replace(' ','&sp;',$_SESSION['panier']['libelleProduit'][$i])."'/>
						<input type=\"hidden\" name=\"action\" value=\"suppression\"/>
						<input type=\"image\"  src=\"style/images/supprimer.png\" border=\"0\" width=\"30px\" height=\"30px\"name=\"action\" value=\"suppression\"/>
						</td>
					</tr>";
	      }
			echo 	"<tr>
						<td colspan=\"3\"></td>
						<td><input type=\"submit\" name=\"action\" value=\"refresh\"/></td>
					</tr>
					<tr>
					</tr>
					<tr>
						<td colspan=\"4\"></td>
						<td>Total:</br>hors frais de port</td>
						<td class=\"total\">".number_format(MontantGlobal(),2,',','')."€</td>
					</tr>
					<tr>
					</tr>
					<tr>
						<td colspan=\"3\"></td>
						<td colpsan=\"2\"><a href=\"etape1.php\"><img class=\"commander\" src=\"style/images/caisse.png\" border=\"0\"></a></td>
					</tr";
	   }
	}
	?>
</table>
</form>


Merci de votre aide


A voir également:

1 réponse

Zep3k!GnO Messages postés 2025 Date d'inscription   Statut Membre Dernière intervention   200
 
Normal, regardes un peu ce que tu t'envoies en valeurs POST, je pense que tu vas comprendre ;)
<?php
echo "<pre>".print_r($_POST, 1)."</pre>";
?>

P.S: faut essayer de débugger des fois aussi à lieu de demander direct...
0