Probleme panier dans la coception d'un site e commerce

josianebsv Messages postés 3 Date d'inscription mercredi 25 mars 2015 Statut Membre Dernière intervention 25 mars 2015 - 25 mars 2015 à 14:11
josianebsv Messages postés 3 Date d'inscription mercredi 25 mars 2015 Statut Membre Dernière intervention 25 mars 2015 - 25 mars 2015 à 16:10
Bonjour,
j'ai une préoccupation je conçoit mon site avec du html et php je suis arrivé au niveaux de cocher un produit pour qu'il puisse aller dans le panier.
j'ai fait une page avec tous les produits le visiteur n'a qu'a cocher ce qui lui plait et valider par la suite .
le lien va vers la page qui doit montrer le total de ce que le visiteur à commandé.
Je suis bloquer au niveau de cocher

2 réponses

jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
25 mars 2015 à 15:12
Bonjour,


Je suis bloquer au niveau de cocher

C'est à dire ??

Pourrais tu nous montrer ton code et nous expliquer en détail le souci rencontré ?
0
josianebsv Messages postés 3 Date d'inscription mercredi 25 mars 2015 Statut Membre Dernière intervention 25 mars 2015
25 mars 2015 à 15:34
voila ma liste de produit avec une case a cocher


<table width="100%" border="0" align="left" cellpadding="0" cellspacing="1">
<tr>
<td height="30" colspan="7" class="tb_head Style15" style="background:url(images/yelo_bg.jpg) repeat-x">GIFT PACKING</td>
</tr>
<tr>
<td height="25" colspan="7" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="45%" class="rcashew">Roasted Cashew</td>
</tr>
</table></td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">Grade</td>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">Price</td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">Price($)</td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"> </td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 180 - 1.00 kg</td>
<input type="hidden" name="qty47" id="qty47" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">1682.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">25.88 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty147" id="qty147" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 240 - 1.00 kg</td>
<input type="hidden" name="qty48" id="qty48" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">1162.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">17.88 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty148" id="qty148" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 320 - 1.00 kg</td>
<input type="hidden" name="qty49" id="qty49" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">940.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">14.46 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty149" id="qty149" value="1" />
</td>
</tr>
<tr>
<td height="30" colspan="7" class="tb_head Style9 Style16" style="background:url(images/yelo_bg.jpg) repeat-x">TIN PACKING</td>
</tr>
<tr>
<td height="25" colspan="7" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="45%" class="rcashew">Roasted Cashew</td>
</tr>
</table></td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">Grade</td>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">Price</td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">Price($)</td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"> </td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 180 - 1.00 kg</td>
<input type="hidden" name="qty42" id="qty42" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">1682.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">25.88 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty142" id="qty142" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 180 - 2.00 kg</td>
<input type="hidden" name="qty41" id="qty41" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">3364.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">51.75 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty141" id="qty141" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 240 - 1.00 kg</td>
<input type="hidden" name="qty44" id="qty44" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">1079.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">16.6 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty144" id="qty144" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 240 - 2.00 kg</td>
<input type="hidden" name="qty43" id="qty43" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">2158.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">33.2 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty143" id="qty143" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 320 - 1.00 kg</td>
<input type="hidden" name="qty46" id="qty46" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">940.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">14.46 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty146" id="qty146" value="1" />
</td>
</tr>
<tr>
<td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">W 320 - 2.00 kg</td>
<input type="hidden" name="qty45" id="qty45" maxlength="9" value=""/>
<td width="16%" height="30" align="center" bgcolor="#FFFFFF" class="subhead">1880.00 </td>
<td width="16%" align="center" bgcolor="#FFFFFF" class="subhead">28.92 </td>
<td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="subhead"><input type="checkbox" name="qty145" id="qty145" value="1" />
</td>
</tr>
</table></td>
</tr>
</table>
<table width="100" border="0" cellspacing="0" cellpadding="0" style="margin-top:20px; margin-left:575px ">
<tr>
<td height="20" align="center" ><img src="foto/addcartbttn.png" width="100" height="28" /></td>
</tr>
</table>
</form> <h1><br />
</h1>
</td>
<td width="400" valign="top"><br />
 <br />
<table width="400" border="0" align="right" cellpadding="0" cellspacing="0" id="leftcol">

<tr>
<td width="314" class="smallText"><p> </p>
<p> </p>
<p> </p>
<p> </p>
<table width="200" border="1" align="right" bgcolor="#5C743D">
<tr>
<td bgcolor="#5C743D"><div align="center"><span class="Style11">News & Event</span> </div></td>
</tr>
<tr>
<td><span class="Style13"><a href="news.php">Applications of the Appointments of Aents / Distributors for Nila Cashew </a></span></td>
</tr>
<tr>
<td><div align="right" class="Style14">VIEW ALL </div></td>
</tr>
</table> <p> </p>
<p> </p>
<p> </p>
<p> </p>
<p align="right"><img src="foto/reciepe_img.jpg" width="248" height="66" /></p>
<p> </p></td>
</tr>
</table> </td>
</tr>
<tr>
<td width="144"><img src="foto/payment_options_sans_mc.gif" width="127" height="127" /></td>
<td width="487"><p> </p>
<p> </p>
<p> </p>
<p> </p></td>
<td width="113"><div>

</div>

j'ai juste prix le tableau qui s'affiche quand le visiteur veut deja acheter

voila mon code ajout panier
ajout

<?php
// caddie_add.php... sert à ajouter un produit...
session_start();
if(isset($_GET['designation']) && isset($_GET['qte']))
{
// si on a spécifié un produit anisi qu'une quantité :
// on vérifie si un panier existe déja...

if(session_is_registered('bag') && is_array($bag))
{

// si le panier existe déja...
$nbprod = count($bag);
// on compte le nombre d'éléments dans le panier...
for($i=0;$i<$nbprod;$i++)
{
// on fait une boucle qui va passer en revue chaque produit du panier
// pour voir si le produit que l'on veut rajouter existe déja
if($bag[$i]['designation'] == $_GET['designation'])
{
// le produit existe...
$prodin = "true";
// inscrit dans une variable que le produit existe...
$prodline = $i;
// et on précise aussi quel est son emplacment dans le caddie
}
}
if(isset($prodin) && $prodin == "true")
{
// si le produit existe déja...
// ...la quantité précédente est effacée...
array_splice($bag,$prodline,1);
// ...pour laisser place à celle qui le client vient de rajouter...
array_push($panier,array("designation" => $_GET['designation'],"qte" => $_GET['qte']));
}
else
{
// sinon on rajoute le produit dans le panier tt simplement...
array_push($bag,array("bag" => $_GET['bag'],"qte" => $_GET['qte']));
}
header("Location: listepduits.php");
// on peut faire une redirection vers une page qui va faire la liste de tous les produits...
}
else
{
// si le panier n'existe pas...
session_register('bag');
// on le créer...
$bag = array ();
// on rajoute le produit et la quantité...
array_push($bag,array("designation" => $_GET['designation'],"qte" => $_GET['qte']));
// le panier à été crée...
header("Location: listepduits.php");
// on peut faire une redirection vers une page qui va faire la liste de tous les produits...
}
}
else
{
// les variable prod et qtte n'existent pas...
header("Location: listepduits.php");
}
?>
####################
<?php
// panier_update.php... ...sert à modifier la quantité d'un produit...
session_start();

if(isset($_GET['designation']) && isset($_GET['qte']))
{
// on vérifie qu'un produit et une 'nouvelle' quantité ont été spécifés...
// si oui,
if($_GET['qte'] != 0)
{
// si la 'nouvelle' quantité est différente de zéro....
$nbprod = count($bag);
for($i=0;$i<$nbprod;$i++)
{
// on fait une boucle qui passe en revue chaque élément du panier...
if ($bag[$i]['designation'] == $_GET['designation'])
{
// lorsque l'on tombe sur le produit à modifier,
// on donne la valeur de la 'nouvelle' quantité à la quantité du produit dan sle panier...
$bag[$i] = array("designation" => $_GET['designation'],"qte" => $_GET['qte']);
}
}
}
else
{
// si la 'nouvelle' quantité est égale à 0, ca revient au même que de supprimer...
$nbprod = count($bag);
for($i=0;$i<$nbprod;$i++)
{
// on fait une boucle qui passe en rebue tout le panier...
if($bag[$i]['designation'] == $_GET['designation'])
{
// dès qu'on tombe sur la valeur à 'modifier'(ici en l'occurence il s'agit de supprmier ..)
array_splice($bag,$i,1);
}
}
}
header("Location: listepduits.php");
// on redirige le client vers une page avec la liste de produits...
}
?>
############################
<?php
// caddie_del.php... ...sert à supprimer un élément du caddie...
session_start();

if(isset($_GET['bag']))
{
// si un produit ets spécifié.;;
$nbprod = count($bag);
for($i=0;$i<$nbprod;$i++)
{
// on fait une boucle qui parcours le panier...
if($bag[$i]['designation'] == $_GET['designation'])
{
// une fois arrivé au produit voulu, on le supprime...
array_splice($bag,$i,1);
}
}
header("Location: listepduits.php");
// on redirige le client vers une page qui liste les produits & les quantités...
}
?>


mon problème justement c'est comme mettre tout çà au clair ajouter supprimer bref çà me creuse et j'ai une grave pression
0
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
25 mars 2015 à 15:58
Déjà... évite d'utiliser le GET
Préfère le POST...

Ensuite .. pour tes checkbox . utilises plutôt un tableau de checkbox avec comme value... le nom du produit...
par exemple :
<input type="checkbox" name="qty[]" id="qty145" value="qty145"
<input type="checkbox" name="qty[]" id="qty146" value="146"


ce qui te permettra de boucler dessus dans ton fichier de traitement
un truc du genre :
<?php

if(isset($_POST)){
  $produits = isset($_POST['qty'])?$_POST['qty']:array();
  echo "<br> Vous avez selectionné ". count($produits). " produits :";
  foreach($produits as $produit){
    echo "<br> - ".$produit;
  }   
}


Ensuite... pour conserver ton "Panier" en mémoire ... (avant de le valider pour acheter par exemple...) le mieux est d'utiliser les variables de SESSION. (je te laisse regarder sur le net comment s'en servir)
0
josianebsv Messages postés 3 Date d'inscription mercredi 25 mars 2015 Statut Membre Dernière intervention 25 mars 2015
25 mars 2015 à 16:10
ok je travaille dessus et j tient informer la toile plus tard car je suis debout debuit tres tot grrrrrrrr and i need to sleep
0
Rejoignez-nous