-
Notifications
You must be signed in to change notification settings - Fork 2
/
cart.php
85 lines (81 loc) · 2.15 KB
/
cart.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
<?php
/*
* Este archio muestra los productos en una tabla.
*/
session_start();
include "php/conection.php";
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Carrito</h1>
<a href="./products.php" class="btn btn-default">Productos</a>
<br><br>
<?php
/*
* Esta es la consula para obtener todos los productos de la base de datos.
*/
$products = $con->query("select * from product");
if(isset($_SESSION["cart"]) && !empty($_SESSION["cart"])):
?>
<table class="table table-bordered">
<thead>
<th>Cantidad</th>
<th>Producto</th>
<th>Precio Unitario</th>
<th>Total</th>
<th></th>
</thead>
<?php
/*
* Apartir de aqui hacemos el recorrido de los productos obtenidos y los reflejamos en una tabla.
*/
foreach($_SESSION["cart"] as $c):
$products = $con->query("select * from product where id=$c[product_id]");
$r = $products->fetch_object();
?>
<tr>
<th><?php echo $c["q"];?></th>
<td><?php echo $r->name;?></td>
<td>$ <?php echo $r->price; ?></td>
<td>$ <?php echo $c["q"]*$r->price; ?></td>
<td style="width:260px;">
<?php
$found = false;
foreach ($_SESSION["cart"] as $c) { if($c["product_id"]==$r->id){ $found=true; break; }}
?>
<a href="php/delfromcart.php?id=<?php echo $c["product_id"];?>" class="btn btn-danger">Eliminar</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<form class="form-horizontal" method="post" action="./php/process.php">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email del cliente</label>
<div class="col-sm-5">
<input type="email" name="email" required class="form-control" id="inputEmail3" placeholder="Email del cliente">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Procesar Venta</button>
</div>
</div>
</form>
<?php else:?>
<p class="alert alert-warning">El carrito esta vacio.</p>
<?php endif;?>
<br><br><hr>
<p>Powered by <a href="http://evilnapsis.com/" target="_blank">Evilnapsis</a></p>
</div>
</div>
</div>
</body>
</html>