-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
executable file
·131 lines (122 loc) · 6.57 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
<?php
require "./header.php";
$items=$_SESSION['cart']['items'];
if(isset($_SESSION['quantityError'])){
unset($_SESSION['quantityError']);
}
// check items in cart are out of stock
foreach($items as $product_id=>$qty){
$id=substr($product_id,2);
$stmt=$pdo->prepare("select * from products where id =?");
$stmt->execute([$id]);
$productInCart=$stmt->fetch(PDO::FETCH_OBJ);
// check user pick product quantity is greater than real product's quantity in database
if($productInCart->quantity<$qty){
$_SESSION["quantityError$productInCart->id"]="sorry,we have not enough in stock.please reduce quantity limit";
unset($_SESSION['cart']['items'][$product_id]);
header ("location:product_detail.php?id=$productInCart->id;");
}
}
?>
<!--================Cart Area =================-->
<section class="cart_area">
<div class="container">
<div class="cart_inner">
<div class="table-responsive">
<?php if(isset($_SESSION['cart']) && !empty($_SESSION['cart']['items'])){ ?>
<table class="table">
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total</th>
<th scope="col">#</th>
</tr>
</thead>
<tbody>
<?php
$items=$_SESSION['cart']['items'];
$subtotal=0;
foreach($items as $product_id=>$qty) :
//$product_id = 'id2'
$id=substr($product_id,2);
// echo ($id);
$stmt=$pdo->prepare("select * from products where id =?");
$stmt->execute([$id]);
$product=$stmt->fetch(PDO::FETCH_OBJ);
$total=$product->price*$qty;
$subtotal+=$product->price*$qty;
?>
<tr>
<td>
<div class="media">
<div class="d-flex">
<a href="product_detail.php?id=<?=$product->id;?>">
<img src="./admin/images/products/<?=$product->image;?>" width="100" height="100">
</a>
</div>
<div class="media-body">
<p><?= $product->name; ?></p>
</div>
</div>
</td>
<td>
<h5 class=""><?= $product->price; ?> kyats</h5>
</td>
<td>
<div class="product_count">
<b><?= $qty; ?></b>
<!-- <input type="text" name="qty" id="sst" maxlength="12" value="<?=$qty?>" title="Quantity:"
class="input-text qty">
<button onclick="var result = document.getElementById('sst'); var sst = result.value; if( !isNaN( sst )) result.value++;return false;"
class="increase items-count" type="button"><i class="lnr lnr-chevron-up"></i></button>
<button onclick="var result = document.getElementById('sst'); var sst = result.value; if( !isNaN( sst ) && sst > 0 ) result.value--;return false;"
class="reduced items-count" type="button"><i class="lnr lnr-chevron-down"></i></button> -->
</div>
</td>
<td>
<!-- total -->
<h5><?= $total; ?>kyats</h5>
</td>
<td>
<a href="clear_item.php?clear_item_id=<?=$product_id?>" class="primary-btn">Remove from cart</a>
</td>
</tr>
<?php endforeach;?>
<tr>
<td></td>
<td></td>
<td></td>
<td>
<h5>Subtotal</h5>
</td>
<td>
<h5><?= $subtotal; ?> kyats</h5>
</td>
</tr>
<tr class="out_button_area">
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<div class="checkout_btn_inner d-flex align-items-center">
<a class="gray_btn" href="./index.php">Continue Shopping</a>
<a class="primary-btn" href="./confirmation.php">Order Submit</a>
<a class="gray_btn" href="clear_items.php">Clear Items</a>
</div>
</td>
</tr>
</tbody>
</table>
<?php } else {?>
<h2>No Items in the cart yet!</h2>
<a class="primary-btn" href="./index.php">Go Back Shopping</a>
<?php } ?>
</div>
</div>
</div>
</section>
<!--================End Cart Area =================-->
<?php require "footer.php" ?>