-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
141 lines (130 loc) · 6.34 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
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
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ayuruveda | Cart</title>
<!-- Common Tags -->
<?php require('includes/head.php') ?>
</head>
<body>
<!-- Navbar and Header -->
<?php require('includes/navbar.php') ?>
<section style="height: 100vh;">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-12">
<div style="display:<?php if(isset($_SESSION['showAlert'])){echo $_SESSION['showAlert'];}else {echo 'none';} unset($_SESSION['showAlert']); ?>"
class="alert alert-success alert-dismissible mt-4" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong><?php if(isset($_SESSION['message'])){echo $_SESSION['message'];} unset($_SESSION['showAlert']); ?></strong>
</div>
<div class="table-responsive mt-4">
<table class="table table-bordered table-striped text-center">
<thead>
<tr>
<td colspan="7">
<h4 class="text-center text-info m-0">
Products in your cart!
</h4>
</td>
</tr>
<tr>
<th>Image</th>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Total Price</th>
<th>
<a href="action.php?clear=all" class="badge bg-danger text-white p-1"
onclick="return confirm('Are you sure want to clear your cart?');">
Clear Cart
</a>
</th>
</tr>
</thead>
<tbody>
<?php
include './connection/connect.php';
$stmt = $con->prepare("SELECT * FROM cart");
$stmt->execute();
$result = $stmt->get_result();
$grand_total = 0;
while($row = $result->fetch_assoc()):
?>
<tr>
<input type="hidden" class="pid" value="<?= $row['id'] ?>">
<td><img src="<?= $row['product_image'] ?>" height="50" width="50"></td>
<td><?= $row['product_name'] ?></td>
<td>Rs. <?= number_format($row['product_price'],2); ?></td>
<input type="hidden" class="pprice" value="<?= $row['product_price'] ?>">
<td><input type="number" class="from-control itemQty" value="<?= $row['qty'] ?>"
style="width: 55px;"></td>
<td>Rs. <?= number_format($row['total_price'],2); ?></td>
<td>
<a href="action.php?remove=<?= $row['id'] ?>" class="text-danger lead"
onclick="return confirm('Are you sure want to remove this item?');">
<i class="fa-solid fa-trash-can"></i>
</a>
</td>
</tr>
<?php $grand_total +=$row['total_price']; ?>
<?php endwhile; ?>
<tr>
<td colspan="2">
<a href="product.php" class="btn btn-success">
<i class="fa-solid fa-cart-plus"></i> Continue Shopping
</a>
</td>
<td colspan="2"><b>Grand Total</b></td>
<td>Rs. <?= number_format($grand_total,2); ?></td>
<td>
<a href="checkout.php"
class="btn btn-info <?= ($grand_total>1)?"":"disabled"; ?>">
<i class=" fa-solid fa-credit-card"></i> Checkout
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<!-- Navbar and Header -->
<?php require('includes/footer.php') ?>
<script type="text/javascript">
$(document).ready(function() {
$(".itemQty").on('change', function(){
var $el = $(this).closest('tr');
var pid = $el.find(".pid").val();
var pprice = $el.find(".pprice").val();
var qty = $el.find(".itemQty").val();
location.reload(true);
$.ajax({
url: 'action.php',
method: 'post',
cache: false,
data: {qty:qty,pid:pid,pprice:pprice},
success: function(response){
console.log(response);
}
})
});
load_cart_item_number();
function load_cart_item_number() {
$.ajax({
url: 'action.php',
method: 'get',
data: {
cartItem: "cart_item"
},
success: function(response) {
$("#cart-item").html(response);
}
});
}
});
</script>
</body>
</html>