par
stefane321 » 15 déc. 2006, 23:41
Bonjour,
Après bien des heures d'ssais et d'erreur j'ai presque terminé mon panier d'achat.
Je bloque cependant sur la suppression d'article.
Mon panier affiche tout les articles un en dessous des autres avec chacun une case à cocher et au bas du panier qui est en soit un formulaire il y a un bouton submit qui sert à retirer du panier:
Code de l'affichage du panier:
sous_total();
echo "<form name=\"form_qte\" action=\"panier3.php\" method=\"post\">\n";
echo "<table align=\"center\" width=\90%\" class=\"border\">\n";
echo "<tr>\n";
echo "<td colspan=\"5\" class=\"border3\" align=\"center\"><b>Voici le contenu de votre panier</b></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"border2\"><b>Produit:</b></td>\n";
echo "<td class=\"border2\"><b>Quantité:</b></td>\n";
echo "<td class=\"border2\"><b>Format:</b></td>\n";
echo "<td class=\"border2\" align=\"center\"><b>Prix:</b></td>\n";
echo "<td class=\"border2\"><b>Supprimer:</b></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"5\"><input type=\"hidden\" name=\"page_retour\" value=\"".$_POST["page_retour"]."\"></td>\n";
echo "</tr>\n";
$nb_produits = 0;
$nb_produits = count($_SESSION["panier"]["id_produit"]);
for($i = 0; $i < $nb_produits; $i++)
{
echo "<tr>\n";
echo "<td class=\"border2\">".$_SESSION['panier']['nom_produit'][$i]."<input type=\"hidden\" name=\"nom_produit_".$_SESSION["panier"]["id_produit"][$i]."\" value=\"".$_SESSION['panier']['nom_produit'][$i]."\">";
//echo "<input name=\"choix[]\" type=\"hidden\" value=\"".$_SESSION["panier"]["id_produit"][$i]."\">\n";
echo "<input type=\"hidden\" name=\"id_produit_".$_SESSION["panier"]["id_produit"][$i]."\" value=\"".$_SESSION["panier"]["id_produit"][$i]."\"></td>\n";
echo "<td class=\"border2\"><input type=\"text\" name=\"qte_".$_SESSION["panier"]["id_produit"][$i]."\" value=\"".$_SESSION['panier']['qte'][$i]."\" size=\"2\"></td>\n";
echo "<td class=\"border2\">".$_SESSION['panier']['nom_format'][$i]."<input type=\"hidden\" name=\"nom_format_".$_SESSION["panier"]["id_produit"][$i]."\" value=\"".$_SESSION['panier']['nom_format'][$i]."\">\n";
echo "<input type=\"hidden\" name=\"format_id_".$_SESSION["panier"]["id_produit"][$i]."\" value=\"".$_SESSION['panier']['format_id'][$i]."\"></td>\n";
echo "<td class=\"border2\" align=\"right\">".$_SESSION['panier']['prix'][$i]." $ <input type=\"hidden\" name=\"prix_".$_SESSION["panier"]["id_produit"][$i]."\" value=\"".$_SESSION['panier']['prix'][$i]."\"></td>\n";
echo "<td class=\"border2\" align=\"right\"><input name=\"choix[]\" type=\"checkbox\" value=\"".$_SESSION["panier"]["id_produit"][$i]."\"></td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class=\"border2\">Sous-total :</td>\n";
echo "<td class=\"border2\" colspan=\"4\" align=\"right\">".$GLOBALS["sous_total"]." $ <input name=\"sous_total\" type=\"hidden\" value=\"".$GLOBALS["sous_total"]."\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"border2\">TPS :</td>\n";
echo "<td class=\"border2\" colspan=\"4\" align=\"right\">".$GLOBALS["tps"]." $ <input name=\"tps\" type=\"hidden\" value=\"".$GLOBALS["tps"]."\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"border2\">TVQ:</td>\n";
echo "<td class=\"border2\" colspan=\"4\" align=\"right\">".$GLOBALS["tvq"]." $ <input name=\"tvq\" type=\"hidden\" value=\"".$GLOBALS["tvq"]."\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Total :</td>\n";
echo "<td colspan=\"4\" align=\"right\">".$GLOBALS["total"]." $ <input name=\"total\" type=\"hidden\" value=\"".$GLOBALS["total"]."\"></td>\n";
echo "</tr>\n";
echo "</table>\n";
Mon problème est qu'il ne supprime pas le produit coché mais tout le reste.
Voici mon code qui retire du panier:
if(isset($_POST['retirer']))
{
$_SESSION['panier_tmp'] = array();
$_SESSION['panier_tmp']['id_produit'] = array();
$_SESSION['panier_tmp']['nom_produit'] = array();
$_SESSION['panier_tmp']['format_id'] = array();
$_SESSION['panier_tmp']['nom_format'] = array();
$_SESSION['panier_tmp']['qte'] = array();
$_SESSION['panier_tmp']['prix'] = array();
foreach($_POST["choix"] as $i)
{
$nb_produits = 0;
$nb_produits = count($_SESSION["panier"]["id_produit"]);
for($y = 0; $y < $nb_produits; $y++)
{
if($_SESSION["panier"]["id_produit"][$y] != $_POST["id_produit_".$i.""])
{
array_push($_SESSION['panier_tmp']['id_produit'],$_POST['id_produit_'.$i.'']);
array_push($_SESSION['panier_tmp']['nom_produit'],$_POST['nom_produit_'.$i.'']);
array_push($_SESSION['panier_tmp']['format_id'],$_POST['format_id_'.$i.'']);
array_push($_SESSION['panier_tmp']['nom_format'],$_POST['nom_format_'.$i.'']);
array_push($_SESSION['panier_tmp']['qte'],$_POST['qte_'.$i.'']);
array_push($_SESSION['panier_tmp']['prix'],$_POST['prix_'.$i.'']);
}
}
$_SESSION['panier'] = $_SESSION['panier_tmp'];
unset($_SESSION['panier_tmp']);
}
}
Pouvez-vous m'aider svp?