-
Notifications
You must be signed in to change notification settings - Fork 2
/
panier.php
126 lines (112 loc) · 3.74 KB
/
panier.php
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
<?php session_start();
include("connection.php");
function ajouter_produit(){
$requete="SELECT * FROM Produits WHERE `product_id`=".$_GET['product_id']."";
$idcom=connex("p1306716","Myparam");
$result=@mysql_query($requete,$idcom);
if(!$result){
echo "Lecture impossible";
}
else{
if(!isset($_SESSION['panier'])){
$_SESSION['panier'] = array();
}
$produit=array();
while($ligne=mysql_fetch_array($result,MYSQL_NUM)){
$new_fruit = array( 'id' => $ligne[0],
'name' => $ligne[1] ,
'description' => $ligne[2] ,
'qte_max' => $ligne[3] ,
'prix' => $ligne[4] ,
'qte_voulu' => $_GET['qte_voulu']);
}
for($i=0;$i<=count($_SESSION['panier']);$i++){
if($_SESSION['panier'][$i]['id'] == $new_fruit['id']){
$_SESSION['panier'][$i]['qte_voulu'] += $new_fruit['qte_voulu'];
$is_add = true;
}
}
if(!$is_add){
array_push($_SESSION['panier'],$new_fruit);
}
}
header("Location: http://localhost/projetBoutiqueBio/index.php");
}
function afficher_panier(){
if(isset($_SESSION['panier'])){
foreach($_SESSION['panier'] as $produit){
echo "<tr>";
echo "<td class=valeur_prod>".$produit['name']."</td>";
echo "<td class=valeur_prod>".$produit['description']."</td>";
echo "<td class=valeur_prod>".$produit['qte_max']."</td>";
echo "<td class=valeur_prod>".$produit['prix']."</td>";
echo "<td class=valeur_prod>".$produit['qte_voulu']."</td>";
echo "<td><a href='panier.php?clean_id=".$produit['id']."' class=bouton_produit >Supprimer article</a></td>";
echo "</tr>";
}
}
}
function cacul_prix_total(){
$prix_total = 0;
if(isset($_SESSION['panier'])){
foreach($_SESSION['panier'] as $produit){
$prix_total += $produit['prix']*$produit['qte_voulu'];
}
}
return $prix_total;
}
function supprimer_produit(){
for($i=0;$i<=count($_SESSION['panier']);$i++){
if($_SESSION['panier'][$i]['id'] == $_GET['clean_id']){
unset($_SESSION['panier'][$i]);
}
}
header("Location: panier.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content= "text/html;charset=UTF-8" />
<title>Les produits bios du pays</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
/*-----------------------------------------vider panier----------------------------------------------------------------*/
if(isset($_GET['clean_all'])){
$_SESSION['panier']=NULL;
session_destroy();
header("Location: http://localhost/projetBoutiqueBio/panier.php");
}
/*-----------------------------------------supprimer un article--------------------------------------------------------*/
if(isset($_GET['clean_id'])){
supprimer_produit();
}
/*-----------------------------------------ajouter un article--------------------------------------------------------*/
if(isset($_GET['product_id']) && isset($_GET['qte_voulu'])){
ajouter_produit();
}
?>
<?php /*-----------------------------affichage panier-----------------------------*/?>
<div id="container">
<?php include("entete.php");?>
<div id=box_panier class='box'>
<h2>Panier</h2>
<?php
echo "<tr>";
echo "<table cellspacing='0' cellpadding='5' style='border-bottom:grey 1px solid;'>";
echo "<th>Produit</th><th>Description</th><th>En stock</th><th>Prix à l'unité</th><th>Quantité</th><th></th>";
echo "</tr>";
afficher_panier();
echo "</table>";
echo "<div id=prix_total><span>Prix total : </span><span id=panier_bouton style='color:red'>".cacul_prix_total()."</span>€</div>";
echo "<div id=bouton_panier>";
echo "<a href='panier.php?clean_all' class=bouton_produit >Vider le panier</a>";
echo "<a href='validation_commande.php' class=bouton_produit >Valider les achats</a>";
echo "</div>";
?>
</div>
</div>
</body>
</html>