-
Notifications
You must be signed in to change notification settings - Fork 1
/
cart.php
72 lines (65 loc) · 2.7 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
<?php
include_once('commonPHP/headerNav.php');
outputHTMLtags();
outputHeaderNav("Cart");
?>
<!-- website window resolution 1278 x 1940.58 -->
<div class="cart-container">
<?php
session_start();
//Include libraries
require __DIR__ . '/vendor/autoload.php';
//Create instance of MongoDB client
$mongoClient = (new MongoDB\Client);
$db = $mongoClient->perfumefest;
$cart_collection = $db->cart;
// checking if cart collection is empty
if ($cart_collection->count() == 0) {
echo '<h1>Your Bag is emtpy...</h1>';
}else
if (array_key_exists("customer", $_SESSION)) {
$customer_id = $_SESSION["customerID"];
// creating find criteria for customer id
$findCriteria = [
"cust_id" => $customer_id,
];
// quering only basket items with the same customer id
$customer_basket = $cart_collection->find($findCriteria);
echo '<h1>Your Bag...</h1>';
foreach ($customer_basket as $item) {
echo ' <div class="order-details">';
echo ' <div class="order-img"><img src="' . $item['Img_url'] . '" alt=""></div>';
echo ' <p class="order-name">Product : ' . $item['Name'] . '</p>';
echo ' Quantity:<input class="order-quantity" value="1" type="text" onfocusout="updateCartTotal()">';
echo ' <button class="remove-item">Remove</button>';
echo ' <p class="order-price">Price : ' . $item['Price'] . '</p>';
echo ' </div>';
}
echo ' <p id="checkoutMsg"></p>';
echo ' <p class="order-total">Total : </p>';
echo ' <button class="checkout-btn" onclick="gotoPayment()">Check-out</button>';
// displaying all cart items when customer is not logged
} else {
$customer_basket = $cart_collection->find();
echo '<h1>Your Bag...</h1>';
foreach ($customer_basket as $item) {
echo ' <div class="order-details">';
echo ' <div class="order-img"><img src="' . $item['Img_url'] . '" alt=""></div>';
echo ' <p class="order-name">Product : ' . $item['Name'] . '</p>';
echo ' Quantity:<input class="order-quantity" value="1" type="text" onfocusout="updateCartTotal()">';
echo ' <button class="remove-item">Remove</button>';
echo ' <p class="order-price">Price : ' . $item['Price'] . '</p>';
echo ' </div>';
}
echo ' <p id="checkoutMsg"></p>';
echo ' <p class="order-total">Total : </p>';
echo ' <button class="checkout-btn" onclick="gotoPayment()">Check-out</button>';
}
?>
<!-- recommened items container -->
</div>
<div class="suggested-items">
</div>
<?php
outputFooter();
?>