-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
214 lines (198 loc) · 8.6 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
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
211
212
213
214
<?php
include_once "includes/sessioncheck.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script src="scripts/jquery-3.5.1.min.js"></script>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="images/shirtlogo.png" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles/style.css" />
<title>Shopping Cart</title>
</head>
<body>
<!-- ----------------------------------- TOP-BAR ----------------------------------- -->
<?php include "includes/storetopbar.php" ?>
<!-- ----------------------------------- TOP-BAR ----------------------------------- -->
<?php
$hasItems = false;
$userId = $_SESSION["userid"];
$rows = mysqlidb::fetchAllRows("SELECT vendor.ShopName,product.ProductId,product.ProductName,product.ProductImage,product.ProductPrice,shopping_cart.CartQuantity,(product.ProductPrice * shopping_cart.CartQuantity) as ProductTotal FROM shopping_cart INNER JOIN product ON product.ProductId = shopping_cart.ProductId INNER JOIN vendor ON vendor.VendorId = product.VendorId WHERE shopping_cart.UserId=$userId");
if (count($rows) > 0) {
$hasItems = true;
}
?>
<!-- ----------------------------------- MODAL ----------------------------------- -->
<?php
if ($hasItems) {
$checkoutTotal = 0;
$totalItems = 0;
foreach ($rows as $row) {
$checkoutTotal += $row["ProductTotal"];
$totalItems += 1;
}
$shippingCost = 5 / 100 * $checkoutTotal;
$gstTax = 6 / 100 * ($shippingCost + $checkoutTotal);
echo '<div class="modal-background modal hidden">
<div class="b-r-0 modal-content center-in-page-abs payment-modal">
<div onclick="DismissModal()" class="material-icons modal-close-button white">close</div>
<div class="modal-body">
<div class="payment-form-container">
<div class="payment-form">
<form action="transaction.php" method="POST">
<div class="form-input-group">
<label for="card_no">Card Number</label>
<input type="text" autocomplete="off" id="card_no" name="card_no" maxlength="16" placeholder="Enter Card Number (16 Digits)" required>
</div>
<div class="flex">
<div class="form-input-group">
<label for="card_exp">Expiration Date</label>
<input type="text" autocomplete="off" maxlength="5" id="card_exp" name="card_exp" placeholder="MM/YY" required>
</div>
<div class="form-input-group">
<label for="card_secret">Security Code (CCV)</label>
<input type="text" autocomplete="off" maxlength="3" id="card_secret" name="card_secret" placeholder="XXX" required>
</div>
</div>
<div class="form-input-group">
<label for="card_holder">Card Holder Name</label>
<input type="text" autocomplete="off" id="card_holder" name="card_holder" placeholder="John Doe" required>
</div>
<div class="form-input-group">
<input type="submit" id="send_transaction" value="Place Order" disabled>
</div>
</form>
</div>
<!-- CHANGE THIS -->
<div class="payment-items">
<div class="payment-items-header">Checkout Items</div>
<div class="payment-items-details flex">
<div class="payment-items-name">
Order Total
</div>
<div class="payment-items-subtotal">
RM ' . number_format($checkoutTotal, 2) . '
</div>
</div>
<div class="payment-items-details flex">
<div class="payment-items-name">
Shipping Cost (5%)
</div>
<div class="payment-items-subtotal">
RM ' . number_format($shippingCost, 2) . '
</div>
</div>
<div class="payment-items-details flex">
<div class="payment-items-name">
SST (6%)
</div>
<div class="payment-items-subtotal">
RM ' . number_format($gstTax, 2) . '
</div>
</div>
<div class="payment-items-total flex">
Total <span>RM ' . number_format($checkoutTotal + $shippingCost + $gstTax, 2) . '</span>
</div>
</div>
<!-- /CHANGE THIS/ -->
</div>
</div>
</div>
</div>';
}
?>
<!-- ----------------------------------- /MODAL/ ----------------------------------- -->
<div class="body-wrapper">
<div></div>
<!-- ----------------------------------- BODY ----------------------------------- -->
<div class="content-wrapper container">
<!-- ----------------------------------- EMPTY CART ----------------------------------- -->
<!-- <div class="center-in-page-abs text-center unselectable">
<div class="material-icons md-144 ruby">shopping_bag</div>
<h1 class="grey">Your shopping cart is empty!</h1>
<a href="index.php">
<div class="w-3 container">
<div class="btn-primary">Go shopping now!</div>
</div>
</a>
</div> -->
<!-- ----------------------------------- /EMPTY CART/ ----------------------------------- -->
<!-- ----------------------------------- CART WITH ITEMS ----------------------------------- -->
<?php
if ($hasItems) {
echo '<div class="cart-item">
<div class="cart-item-header">
<div class="cart-product">Product</div>
<div class="cart-price">Unit Price</div>
<div class="cart-quantity">Quantity</div>
<div class="cart-total">Total Price</div>
<div class="cart-actions">Actions</div>
</div>
<div id="cart-item-body" class="cart-item-body">';
$vendors = [];
foreach ($rows as $row) {
if (!in_array($row["ShopName"], $vendors)) {
array_push($vendors, $row["ShopName"]);
}
}
foreach ($vendors as $vendor) {
echo "<div class=\"cart-item-vendor\">
from <span class=\"cart-item-vendor-name ruby\">$vendor</span>
</div>";
foreach ($rows as $row) {
if ($row["ShopName"] == $vendor) {
$productImage = explode(",", $row["ProductImage"])[0];
echo '<div class="cart-item-details">
<a href="item.php?id=' . $row["ProductId"] . '" class="cart-product ellipsis-truncate">
<img src="' . $productImage . '" alt="">
' . $row["ProductName"] . '
</a>
<div class="cart-price">RM ' . number_format($row["ProductPrice"], 2) . '</div>
<div class="cart-quantity">' . $row["CartQuantity"] . '</div>
<div class="cart-total">RM ' . number_format($row["ProductTotal"], 2) . '</div>
<div class="cart-actions ruby" onclick="RemoveFromCart(' . $row["ProductId"] . ',true)">
Remove
</div>
</div>';
}
}
}
echo '</div>';
} else {
echo '<div class="center-in-page-abs text-center unselectable">
<div class="material-icons md-144 ruby">shopping_bag</div>
<h1 class="grey">Your shopping cart is empty!</h1>
<a href="index.php">
<div class="w-3 container">
<div class="btn-primary">Go shopping now!</div>
</div>
</a>
</div>';
}
?>
</div>
</div>
<?php
if ($hasItems) {
echo '<div class="cart-checkout-area">
<div class="cart-checkout-area-wrapper container content-wrapper">
<div class="cart-checkout-quantity">Merchandise Subtotal (' . $totalItems . ' items)</div>
<div class="cart-checkout-total">RM ' . number_format($checkoutTotal, 2) . '</div>
<div class="cart-checkout-button-container">
<div onclick="ShowModal()" class="cart-checkout-button btn-primary">Checkout</div>
</div>
</div>
</div>';
}
?>
<!-- ----------------------------------- /BODY/ ----------------------------------- -->
<!-- ----------------------------------- FOOTER ----------------------------------- -->
<?php include "includes/footer.php" ?>
<!-- ----------------------------------- /FOOTER/ ----------------------------------- -->
</div>
</body>
<script src="scripts/main.js"></script>
<script src="scripts/cart_page.js"></script>
<?php include "includes/store_scripts.php"; ?>
</html>