-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcart_page.php
More file actions
138 lines (136 loc) · 5.64 KB
/
cart_page.php
File metadata and controls
138 lines (136 loc) · 5.64 KB
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
<?php
session_start();
include('config/dbcon.php');
include('components/header.php');
include('components/navbar.php');
include('components/frontbar.php');
?>
<main class="product_page_container">
<div class="product_details horiz_ruler">
<?php
if(isset($_SESSION['auth'])){
$user_id = $_SESSION['auth_user']['id'];
$sql = "SELECT c.id as cart_id, c.product_qty, p.id as product_id, p.product_name, p.image_1, p.price, p.quantitty
FROM carts c, products p
WHERE c.product_id = p.id AND c.user_id = '$user_id'
ORDER BY c.id DEsC;";
$result = pg_query($connection, $sql);
if ($result) {
if (pg_num_rows($result) > 0) {
?>
<div class="product_in_cart_details1">
<div class="info_dropdown"><span>My cart</span></div>
<hr>
<?php
$initial_amout = 0;
$index = 0;
while ($items = pg_fetch_assoc($result)) {
$initial_amout = $initial_amout + ($items["price"] * $items["product_qty"]);
$index = $index + 1;
$_SESSION['count'] = $index;
?>
<div class="product_in_cart">
<div class="img_container">
<p class="product-name1"><img src="admin/uploads/<?= $items["image_1"]; ?>" alt="<?= $items["image_1"]; ?>"></p>
</div>
<div class="middle_container">
<div class="name_container">
<p class="product-name1"><?= $items["product_name"]; ?></p>
</div>
<div class="prod_qty_container">
<form class="input_btn_container" id="numberForm" action="functions/handle_cart.php" method="post">
<input type="hidden" class="iprice" name="price" value="<?=$items["price"];?>">
<input type="hidden" name="product_id" value="<?= $items["product_id"]; ?>">
<input onchange="subTotal();" class="iquantity" type="number" id="numberInput" value="<?= $items["product_qty"]; ?>" name="product_qty" min="0">
<input type="hidden" name="stock_qty" value="<?= $items["quantitty"]; ?>">
<button type="submit" name="update_cart_btn">Update</button>
</form>
<span class="product-name1">R<span class="itotal"><?= $items["price"] * $items["product_qty"]; ?></span></span>
</div>
</div>
<form class="close_btn_container" action="functions/handle_cart.php" method="post">
<input type="hidden" name="product_id" value="<?= $items["product_id"]; ?>">
<button type="submit" name="delete_prod_btn" class="product-name1"><img src="https://img.icons8.com/ios/50/delete-sign--v1.png" alt="delete-sign--v1"/></button>
</form>
</div>
<hr>
<?php
}
?>
</div>
<div class="product_in_cart_details2">
<div class="product_info_container">
<div class="info_dropdown"><span class="order_s">Order summary</span></div>
<hr>
<div class="initial_amout">
<p>Subtotal</p>
<p>R<span id="gtotal"><?= $initial_amout; ?></span></p>
</div>
<?php
$deliver = 0;
$total = $initial_amout;
if ($initial_amout < 500) {
$deliver = $initial_amout * 0.15;
$total += $deliver;
}
?>
<div class="delivery">
<p>Delivery</p>
<p>
<span><span id="deliver"><?= ($deliver > 0) ? number_format($deliver, 2) : 'FREE'; ?></span></span>
</p>
</div>
<hr>
<div class="final_price">
<p>Total</p>
<p>R<span id="total"><?= number_format($total, 2); ?></span></p>
</div>
<div class="cart_wish_container">
<a href="checkout.php"><input class="add_product_button-js" type="submit" value="Checkout" name="add_to_cart-btn"></a>
</div>
<div class="secure_checkout">
<img src="https://img.icons8.com/ios-glyphs/30/lock--v1.png" alt="lock--v1"/>
<p>Secure Checkout</p>
</div>
</div>
</div>
<?php
} else {
?>
<div class="empty_cart_container">
<div class="empty_cart">
<p>My cart</p>
<div class="cart_container">
<p>Cart is empty</p>
<a href="shop_all.php">Continue Browsing</a>
</div>
</div>
</div>
<?php
}
} else {
?>
<div class="each_category">
<p>Execution Error: <?= pg_last_error($connection); ?></p>
</div>
<?php
}
}else{
?>
<div class="empty_cart_container">
<div class="empty_cart">
<p>My cart</p>
<div class="cart_container">
<p>Cart is empty (<a href="login.php">Click here to Login</a>)</p>
<a href="shop_all.php">Continue Browsing</a>
</div>
</div>
</div>
<?php
}
?>
</div>
</main>
<?php
include('components/footer.php');
?>