-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-cart.php
210 lines (183 loc) · 8.18 KB
/
my-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
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
201
202
203
204
205
206
207
208
209
210
<?php include_once("componet/conn.php"); ?>
<?php
session_start();
if(isset($_SESSION['id'])){
$uid = $_SESSION["id"];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style-index.css">
<link rel="stylesheet" href="style-res.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Acme&family=Barlow:wght@500&family=Quicksand:wght@500&family=Raleway:wght@300&family=Ubuntu:wght@700&display=swap"
rel="stylesheet">
<!-- fonts -->
<title>EZSOP - My cart</title>
</head>
<body>
<div class="mycart">
<div class="cart-back">
<a href="index.php">
<i class="fa-solid fa-arrow-left-long"></i>
<span>Back To Home</span>
</a>
</div>
<div class="mycart-hading">
<i class="fa-solid fa-bag-shopping"></i>
<h1>My Cart</h1>
</div>
<?php
if(!isset($_SESSION['id'])){
?>
<div class="no-item">
<h1>No item added</h1>
<a href="ShopAll.php">
<button>Shop Now</button>
</a>
</div>
<?php
}
elseif(isset($_SESSION['id'])){
$getitemquery = "SELECT * FROM `mycart` where userid={$uid}";
$excgetitem = $con->query($getitemquery);
$items = mysqli_num_rows($excgetitem);
if($items == 0){
echo '<div class="no-item">
<h1>No item added</h1>
<a href="ShopAll.php">
<button>Shop Now</button>
</a>
</div>';
} else{
?>
<div class="cart-section">
<div class="cart-items">
<div class="cart-items-hading">
<h2>cart (<?php echo $items; ?> items)</h2>
<?php
while($res = $excgetitem->fetch_assoc()){
?>
<div class="cart-item-card">
<div class="cart-item-img">
<img src="<?php echo $res["cartimg"] ?>">
</div>
<div class="cart-item">
<div class="item-info">
<div class="cart-item-details">
<div class="cart-item-title">
<h3><?php echo $res["carttitle"] ?></h3>
</div>
<div class="cart-item-desc">
<p><?php echo $res["cartdesc"] ?></p>
</div>
<div class="cart-item-price">
<h1>₹<span class="item-price"><?php echo $res["cartprice"] ?></span></h1>
</div>
</div>
<div class="cart-qty">
<div class="qty-btns">
<div class="btn-mins"><span>-</span></div>
<div class="qty-num"><span class="num"><?php echo $res['cartqty']; ?></span></div>
<div class="btn-plus"><span>+</span></div>
</div>
</div>
</div>
<div class="cart-item-btn">
<div class="item-remove-btn">
<i class="fa-solid fa-trash-can"></i>
<a href="componet/cartremoveitem.php?cid=<?php echo $res["cartid"]; ?>">REMOVE ITEM</a>
</div>
<div class="item-move-btn">
<i class="fa-solid fa-heart"></i>
<a href="#">MOVE TO FAVORITES</a>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<div class="cart-right">
<div class="cart-checkout">
<h3 class="checkout-heading">The Total Amount Of</h3>
<div class="product-prices">
<p>Product amount</p>
<p>₹<span class="item-total-price">0</span></p>
</div>
<div class="product-prices">
<p>Shipping Charge</p>
<p class="shiping-charge">FREE</p>
</div>
<div class="product-prices">
<p>The total amount</p>
<p class="total-price">₹0</p>
</div>
</div>
<div class="cart-buy">
<a href="checkout.php">
<input type="submit" value="Proceed to checkout" name="checkout"/>
</a>
</div>
</div>
</div>
<?php } }?>
</div>
<script>
let minsdiv = document.querySelectorAll(".btn-mins");
let numdiv = document.querySelectorAll(".qty-num");
let plusdiv = document.querySelectorAll(".btn-plus");
let price = document.getElementsByClassName("item-price");
let displaysum = document.querySelector(".item-total-price");
let totalprice = document.querySelector(".total-price");
for (var i = 0; i < plusdiv.length; i++) {
let nums = numdiv[i];
let itemprice = price[i];
plusdiv[i].addEventListener("click", ()=> {
getnum = nums.textContent;
getprice = itemprice.textContent;
intnum = parseInt(getnum,10);
intprice = parseInt(getprice,10);
nums.textContent = intnum + 1;
gettotalprice();
});
minsdiv[i].addEventListener("click", ()=> {
getnum = nums.textContent;
convintnum = parseInt(getnum,10);
if(convintnum > 1){
nums.textContent = convintnum - 1;
}
gettotalprice();
});
}
</script>
<script>
function gettotalprice(){
let sum = 0;
for (i = 0; i < price.length; i++){
var qtycontainer = document.getElementsByClassName('qty-num');
itemprice = price[i].textContent;
itemqty = qtycontainer[i].textContent;
intallprice = parseInt(itemprice,10);
intallqty = parseInt(itemqty,10);
sum = sum + (intallprice * intallqty);
totalprice.textContent ="₹" + (sum );
}
displaysum.textContent = sum;
}
gettotalprice();
</script>
</body>
</html>