bonjour,
J'apprends à créer une boutique, mais ce n'est pas chose évidente !
Heureusement que mes ami Google et forums sont là !
J'avance bien grâce à cette précieuse aide !
Me voici maintenant avec un petit (?) problème.
J'ai une page html "boutique00.php", qui gère 4 listes liées dynamiques.
Mes choix successifs fonctionnent.
C'est donc tout normalement que je détermine mon choix sur la 4e liste.
Et là, c'est "ajaxcategorie04.php" qui est lancé.
Ce programme remplit bien la 2e partie du formulaire (panier).
"ajaxcategorie04.php". Il me crée bien un lien type submit.
Jusque là tout va bien !
J'avance !
Après avoir appuyer sur le bouton "ajouter" (de la page "boutique00.php",
comment faire pour envoyer $qte, $pvhtva... (qui sont calculés dans "ajaxcategorie04.php",
dans des variables de session, pour que je puisse les exploiter par la suite dans la page html "ajouter.php"
qui, elle, permettra de manipuler le panier par la suite (modifier, supprimer ou confirmer la commande).
J'essaie les variables de session, mais cela ne fonctionne pas !
D'avance, je vous remercie pour le temps que vous passerez à m'aider.
Bonne journée.
Voici la partie javascript (qui lance "ajaxcategorie04.php"entre les balises head et /head) de "boutique00.php" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 <script type="text/javascript"> <!-- // categorie03 function gocategorie03() { getXhr(); // On définit ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { // On ne fait quelquechose que si l'on a tout reçu et que le serveur est OK if (xhr.readyState == 4 && xhr.status == 200) { leselect = xhr.responseText; // On se sert de innerHTML pour rajouter les options à la liste document.getElementById('detail').innerHTML = leselect; document.getElementById("loader03").style.display = "none"; } else { document.getElementById("loader03").style.display = "inline"; } } // Ici on va voir comment faire du post xhr.open("POST","php/ajaxcategorie04.php",true); // Ne ps oublier ç pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // Ne ps oublier de poster les arguments // ici l'id de cat01 sel = document.getElementById('categorie03'); idcategorie03 = sel.options[sel.selectedIndex].value; xhr.send("ix="+idcategorie03); // Ouverture du tableau devis var selectValue = getSelectValue('categorie03'); if (selectValue == "" || selectValue == "none") { hidden = 5; } else { hidden = 6; } document.getElementById("tr04").style.display = ""; document.getElementById("tr05").style.display = ""; document.getElementById("tr06").style.display = ""; document.getElementById("tr07").style.display = ""; document.getElementById("tr08").style.display = ""; document.getElementById("tr09").style.display = ""; document.getElementById("tr10").style.display = ""; } --> </script>
Voici la partie html qui gère le formulaire, c'est "boutique00.php" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 <form name="enpanier" action="panier00.php" method="post" target="_self"> <table border="0" align="left" cellspacing="0" id="tableoptions" style="vertical-align:middle;"> <tr> <td width="150"></td> <td width="280"></td> <td width="20"></td> <td width="0"></td> </tr> <tr> <td colspan="4" style="padding:7px;" bgcolor="#0E72B5" class="blanc bold">Prix en ligne instantané</td> </tr> <tr> <td colspan="4" style="padding:7px;"> Afin d'établir un devis,<br>veuillez choisir parmi toutes les options suivantes :</td> </tr> <tr id="tr00"> <td width="136" style="padding:7px;">Document</td> <td width="280" id="td00"> <select name="categorie00" id="categorie00" style="width:280px;" onChange="gocategorie00();" > <option value="none">-- Choisissez, svp ! --</option> <?php require_once("php/connexionMysql.inc.php"); $query = mysql_query("SELECT * FROM shop_categorie00 ORDER BY id"); while ($back = mysql_fetch_assoc($query)) { echo "<option value='".$back['id']."' ><span style='width: 280px;' >".$back['libelle']."</span></option>"; } ?> </select> </td> <td width="20"> <span id="loader00" class="hidden" style="width:20px;"><img src="images/boutique/loader16.gif" alt="loading" width="16" height="16" border="0" align="absmiddle" /></span> </td> <td width="0"> </td> </tr> <tr id="tr01" style="display:none;"> <td width="136" style="padding:7px;">Descriptif</td> <td width="280" id="td01"> <!-- <select name="categorie01" id="categorie01" style="width:280px;"></select> --> </td> <td width="20"> <span id="loader01" class="hidden" style="width:20px;"><img src="images/boutique/loader16.gif" alt="loading" width="16" height="16" border="0" align="absmiddle" /></span> </td> <td width="0"> </td> </tr> <tr id="tr02" style="display:none;"> <td width="136" style="padding:7px;">Format</td> <td width="280" id="td02"> <!-- <select name="categorie02" id="categorie02" style="width:280px;"></select> --> </td> <td width="20"> <span id="loader02" class="hidden" style="width:20px;"><img src="images/boutique/loader16.gif" alt="loading" width="16" height="16" border="0" align="absmiddle" /></span> </td> <td width="0"> </td> </tr> <tr id="tr03" style="display:none;"> <td width="136" style="padding:7px;">Papier</td> <td width="280" id="td03"> <!-- <select name="categorie03" id="categorie03" style="width:280px;"></select> --> </td> <td width="20"> <span id="loader03" class="hidden" style="width:20px;"><img src="images/boutique/loader16.gif" alt="loading" width="16" height="16" border="0" align="absmiddle" /></span> </td> <td width="0"> </td> </tr> </table> <?php $qte=1; ?> <div id="detail" class="c12"> <table> </table> </div> </form>
Voici le fichier "ajaxcategorie04.php" :
Voici "ajouter.php" (dans une version simpliste)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 <?php session_start(); require_once("fonctions-panier.inc.php"); require_once("connexionMysql.inc.php"); echo "<table name='table' id='table' border='0' align='left' cellspacing='0' style='vertical-align:middle;'>"; if (isset($_REQUEST['ix'])) { $query = mysql_query("SELECT * FROM shop_articles". " WHERE id=".$_REQUEST['ix']); while ($back = mysql_fetch_assoc($query)) { $remisehtva = $back['prix_ht'] * $back['remise_pourcentage'] / 100 + $back['remise_valeur'] ; $pvhtva = $back['prix_ht'] - $remisehtva ; $pvtvac = $pvhtva * (100 + $back['taux_tva']) / 100; echo "<tr id='tr04'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td04'><div class='commentaire'>".$back['commentaire']."</div></td> <td width='20'></td><td width='0'></td></tr>"; echo "<tr id='tr05'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td05' class='delai' align='right'>Délai : ".$back['delai']."</td> <td width='20'></td><td width='0'></td></tr>"; echo "<tr id='tr06'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td06'> </td> <td width='20'></td><td width='0'></td></tr>"; echo "<tr id='tr07'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td07' class='c20 bold' align='right'>Prix HTVA : <span class='bleu'>".number_format($pvhtva,2,',',' ')." </span></td> <td width='20'></td><td width='0'></td></tr>"; echo "<tr id='tr08'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td08' class='c15' align='right'>".number_format($pvtvac,2,',',' ')." TVAC</td> <td width='20'></td><td width='0'></td></tr>"; echo "<tr id='tr09'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td09' class='c05' align='right'> </td> <td width='20'></td><td width='0'></td></tr>"; echo "<tr id='tr10' height='48'><td width='136' style='padding-left:7px; padding-right:7px;'></td> <td width='280' id='td10' align='right' class='c15 bold bouton_ajouter' ><a href='ajouter.php' onClick=enpanier.submit() style='padding-right:25px'>Ajouter</a></td> <td width='20'></td><td width='0'></td></tr>"; } $refLigne=$_REQUEST['ix']; $qteLigne=0; $libLigne= $back['designation']; $pvnLigne= $pvhtva; ajouterArticle($refLigne, $libLigne, $qteLigne, $pvnLigne); } echo "</table>"; ?>
Voici enfin un extrait de "fonctions-panier.inc.php" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <?php session_start(); echo "voici les valeurs 0<br>"; echo $_SESSION['panier']['refProduit'][0]."<br>"; echo "voici les valeurs 1<br>"; echo $_SESSION['panier']['refProduit'][1]."<br>"; ?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 <?php /** * Verifie si le panier existe, le créé sinon * @return booleen */ function creationPanier(){ if (!isset($_SESSION['panier'])){ $_SESSION['panier']=array(); $_SESSION['panier']['refProduit'] = array(); $_SESSION['panier']['libProduit'] = array(); $_SESSION['panier']['qteProduit'] = array(); $_SESSION['panier']['pvnProduit'] = array(); $_SESSION['panier']['verrou'] = false; } return true; } /** * Ajoute un article dans le panier * @param string $libProduit * @param int $qteProduit * @param float $pvnProduit * @return void */ function ajouterArticle($refProduit,$libProduit,$qteProduit,$pvnProduit){ //Si le panier existe if (creationPanier() && !isVerrouille()) { //Si le produit existe déjà on ajoute seulement la quantité $positionProduit = array_search($refProduit, $_SESSION['panier']['refProduit']); if ($positionProduit !== false) { $_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit ; } else { //Sinon on ajoute le produit array_push( $_SESSION['panier']['refProduit'],$refProduit); array_push( $_SESSION['panier']['libProduit'],$libProduit); array_push( $_SESSION['panier']['qteProduit'],$qteProduit); array_push( $_SESSION['panier']['pvnProduit'],$pvnProduit); } } else echo "Un problème est survenu veuillez contacter l'administrateur du site."; } ?>
Partager