-
Notifications
You must be signed in to change notification settings - Fork 0
/
tienda.php
200 lines (148 loc) · 4.03 KB
/
tienda.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
require 'database.php';
session_start();
if (isset($_SESSION['user_log'])) {
$records = $fra30->prepare('SELECT dni, nombre, pass FROM clientes WHERE dni = :dni');
$records->bindParam(':dni', $_SESSION['user_log']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$user = null;
if (count($results) > 0) {
$user = $results;
}
}else{
header('Location: index.php');
}
?>
<br> Hola! <?= $user['nombre']; ?>
<a href="logout.php">
Desconectarse.
</a>
<?php
if(isset($_POST["add_to_cart"]))
{
if(isset($_SESSION["shopping_cart"]))
{
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["shopping_cart"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][$count] = $item_array;
}
else
{
echo 'Este Producto ya se encuentra en su carro, si desea cambiar la cantidad hágalo desde el carrito.';
}
}
else
{
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][0] = $item_array;
}
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
if($values["item_id"] == $_GET["id"])
{
unset($_SESSION["shopping_cart"][$keys]);
echo 'Producto removido';
}
}
}
}
$q = "SELECT * FROM productos ORDER BY stock ASC";
$result = mysqli_query($fra31, $q);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{?>
<div>
<form method="post" action="tienda.php?action=add&id=<?php echo $row["id"]; ?>">
<div>
<img src="img/<?php echo $row["id"]; ?>.png" class="img-responsive" /><br />
<input type="hidden" name="hidden_name" value="<?php echo $row["prod"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $row["precio_ven"]; ?>" />
<h4 class="text-info"><?php echo $row["prod"]; ?></h4>
<h4 class="text-info"><?php echo $row["descr"]; ?></h4>
<h4 class="text-info"><?php echo $row["volum"]; ?></h4>
<h4 class="text-danger">$ <?php echo $row["precio_ven"]; ?></h4>
<input type="text" name="quantity" value="1" class="form-control" />
<input type="submit" name="add_to_cart" value="Añadir a la compra" />
</div>
</form>
</div>
<?php
}
}
?>
<div></div>
<br />
<h3>Carro de Compras</h3>
<div>
<table>
<tr>
<th >Producto</th>
<th >Cantidad</th>
<th >Precio</th>
<th >Total</th>
<th >Eliminar</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td><?php echo $values["item_name"]; ?></td>
<td><?php echo $values["item_quantity"]; ?></td>
<td>$ <?php echo $values["item_price"]; ?></td>
<td>$ <?php echo number_format($values["item_quantity"] * $values["item_price"], 2);?></td>
<td><a href="tienda.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span >Eliminar</span></a></td>
</tr>
<?php
$total = $total + ($values["item_quantity"] * $values["item_price"]);
}
?>
<tr>
<td >Total</td>
<td >$ <?php echo number_format($total, 2); ?></td>
<td>
<a href="comprar.php">
<button>Comprar</button>
</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
<br />
</body>
</html>
<?php
if ( $user['dni'] == "41669448"){
?>
<a href='soloyo41.php'>Admin</a>
<?php
}
?>