salut mes amis je suis le tuto proposer dans ce site ,,, pour un petit e-commerce, bon voila j'ai créé un les fonctionnalité supprimer un article du panier et supprimer un panier marche , mon problème c'est que lorsque j'ajoute un article en panier meme pour la 1er fois il m'affiche cette erreur Notice: Undefined variable: prixProduit in
voila le résutat en image
et aussi le code de la page fonction_panier
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168 <?php function creationPanier(){ try { $db = new PDO('mysql:host=localhost;dbname=site-e-commerce','root',''); $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(Exception $e){ echo 'une erreur est survenu'; die(); } if(!isset($_SESSION['panier'])){ $_SESSION['panier']=array(); $_SESSION['panier']['libelleProduit'] = array(); $_SESSION['panier']['qteProduit'] = array(); $_SESSION['panier']['prixProduit'] = array(); $_SESSION['panier']['verrou'] = false; $select = $db->query("SELECT tva FROM products"); $data = $select->fetch(PDO::FETCH_OBJ); $_SESSION['panier']['tva'] = $data->tva; } return true; } function ajouterArticle($libelleProduit, $qteProduit, $prixPoduit){ if(creationPanier() && !isVerouille()){ $positionProduit = array_search($libelleProduit, $_SESSION['panier']['libelleProduit']); if($positionProduit !== false){ $_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit; }else{ array_push( $_SESSION['panier']['libelleProduit'],$libelleProduit); array_push( $_SESSION['panier']['qteProduit'],$qteProduit); array_push( $_SESSION['panier']['prixProduit'],$prixProduit); } }else{ echo 'Erreur, veillier contacter l\'administrateur'; } } function modifierQteArticle($libelleProduit,$qteProduit){ if(creationPanier() && !isVerouille()){ if($qteProduit > 0){ $positionProduit = array_search($libelleProduit, $_SESSION['panier']['libelleProduit']); if($positionPoduit !== false){ $_SESSION['panier']['qteProduit'][$positionProduit] = $qteProduit; } }else{ supprimerArticle($libelleProduit); } }else{ echo 'Erreur, veulliez contacter un administrateur'; } } function supprimerArticle($libelleProduit){ if(creationPanier() && !isVerouille()){ $tmp = array(); $tmp['libelleProduit']=array(); $tmp['qteProduit']=array(); $tmp['prixProduit']=array(); $tmp['verrou']=$_SESSION['panier']['verrou']; $tmp['tva']=$_SESSION['panier']['tva']; for($i = 0; $i < count($_SESSION['panier']['libelleProduit']) ;$i++){ if($_SESSION['panier']['libelleProduit'][$i] !== $libelleProduit){ array_push($tmp['libelleProduit'],$_SESSION['panier']['libelleProduit'][$i]); array_push($tmp['qteProduit'],$_SESSION['panier']['qteProduit'][$i]); array_push($tmp['prixProduit'],$_SESSION['panier']['prixProduit'][$i]); } } $_SESSION['panier'] = $tmp; unset($tmp); }else{ echo 'Erreur, veulliez contacter un administrateur'; } } function montantGlobal(){ $total=0; for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++){ $total += $_SESSION['panier']['qteProduit'][$i]*$_SESSION['panier']['prixProduit'][$i]; } return $total; } function montantGlobalTVA(){ $total=0; for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++){ $total += $_SESSION['panier']['qteProduit'][$i]*$_SESSION['panier']['prixProduit'][$i]; } return $total + $total*$_SESSION['panier']['tva']/100; } function supprimerPanier(){ unset($_SESSION['panier']); } function isVerouille(){ if(isset($_SESSION['panier'])&& $_SESSION['panier']['verrou']){ return true; }else{ return false; } } function compterArticle(){ if(isset($_SESSION['panier'])){ return count($_SESSION['panier']['libelleProduit']); }else{ return 0; } } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="../style/bootstrap.css"> <title>Document sans titre</title> </head> <body> </body> </html>
et aussi le code pour ma page panier.php
merci pour votre aide
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 <?php /* ini_set("display_errors",0);error_reporting(0); */ ?> <?php require_once('includes/hender.php'); require_once('includes/sidebar.php'); require_once('includes/functions_panier.php'); $erreur = false; $action = (isset($_POST['action'])?$_POST['action']:(isset($_GET['action'])?$_GET['action']:NULL)); if($action !== NULL){ if(!in_array($action, array('ajout','suppression','refresh'))) $erreur = true; $l = (isset($_POST['l'])?$_POST['l']:(isset($_GET['l'])?$_GET['l']:NULL)); $q = (isset($_POST['q'])?$_POST['q']:(isset($_GET['q'])?$_GET['q']:NULL)); $p = (isset($_POST['p'])?$_POST['p']:(isset($_GET['p'])?$_GET['p']:NULL)); $l = preg_replace('#\v#','',$l); $p = floatval($p); 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($l,$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; } } ?> <form method="post" action=""> <table width="400"> <tr> <td colspan="4"><h3>Votre panier :</h3></td> </tr> <tr> <td><h5>Libellé produit</h5></td> <td><h5>Prix unitaires</h5></td> <td><h5>Qantitées</h5></td> <td><h5>TVA</h5></td> <td><h5>Action</h5></td> </tr> <?php if(isset($_GET['deletepanier']) && $_GET['deletepanier']==true){ supprimerPanier(); } if(creationPanier()){ $nbPorduit = count($_SESSION['panier']['libelleProduit']); if($nbPorduit <= 0){ echo '<p style="font-size:30px; color:Red;">Oops, Panier Vide !</p>'; }else{ for($i = 0; $i < $nbPorduit; $i++){ ?> <tr> <td><br><?php echo $_SESSION['panier']['libelleProduit'][$i]; ?></td> <td><br><?php echo $_SESSION['panier']['prixProduit'][$i];?></td> <td><br><input name="q[]" value="<?php $_SESSION['panier']['qteProduit'][$i]?>" size="5"/></td> <td><br><?php echo $_SESSION['panier']['tva']."%";?></td> <td><br><a href="panier.php?action=suppression&l=<?php echo rawurlencode($_SESSION['panier']['libelleProduit'][$i]);?>">Supprimer</a></td> </tr> <?php } ?> <tr> <td colspan="2"> <h5>Total : <?php echo montantGlobal(); ?></h5><br> <h5>Total avec TVA : <?php echo montantGlobalTVA(); ?></h5> </td> </tr> <tr> <td colspan="4"> <input type="submit" value="rafraichir"/> <input type="hidden" name="action" value="refresh"/> <a href="?deletepanier=true">Supprimer le panier</a> </td> </tr> <?php } } ?> </table> </form> <?php require_once('includes/footer.php'); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="style/bootstrap.css"> <title>Document sans titre</title> </head> <body> </body> </html>
Partager