-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
124 lines (105 loc) · 4.07 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
<?php
session_start();
// connect to database
include 'config/database.php';
// include objects
include_once "objects/product.php";
include_once "objects/product_image.php";
include_once "objects/cart_item.php";
// get database connection
$database = new Database();
$db = $database->getConnection();
// initialize objects
$product = new Product($db);
$product_image = new ProductImage($db);
$cart_item = new CartItem($db);
// set page title
$page_title="Cart";
// include page header html
include 'layout_head.php';
$action = isset($_GET['action']) ? $_GET['action'] : "";
echo "<div class='col-md-12'>";
if($action=='removed'){
echo "<div class='alert alert-info'>";
echo "Product was removed from your cart!";
echo "</div>";
}else if($action=='quantity_updated'){
echo "<div class='alert alert-info'>";
echo "Product quantity was updated!";
echo "</div>";
}else if($action=='exists'){
echo "<div class='alert alert-info'>";
echo "Product already exists in your cart!";
echo "</div>";
}else if($action=='cart_emptied'){
echo "<div class='alert alert-info'>";
echo "Cart was emptied.";
echo "</div>";
}else if($action=='updated'){
echo "<div class='alert alert-info'>";
echo "Quantity was updated.";
echo "</div>";
}else if($action=='unable_to_update'){
echo "<div class='alert alert-danger'>";
echo "Unable to update quantity.";
echo "</div>";
}
echo "</div>";
// $cart_count variable is initialized in navigation.php
if($cart_count>0){
$cart_item->user_id=$_SESSION['user_id'];
$stmt=$cart_item->read();
$total=0;
$item_count=0;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
$sub_total=$price*$quantity;
echo "<div class='cart-row'>";
echo "<div class='col-md-8'>";
// product name
echo "<div class='product-name m-b-10px'>";
echo "<h4>{$name}</h4>";
echo "</div>";
// update quantity
echo "<form class='update-quantity-form' action='update_quantity.php' method='GET'>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='input-group'>";
echo "<input type='number' name='quantity' value='{$quantity}' class='form-control cart-quantity' min='1' />";
echo "<input type='hidden' name='id' value='{$id}' />";
echo "<span class='input-group-btn'>";
echo "<button class='btn btn-default update-quantity' type='submit'>Update</button>";
echo "</span>";
echo "</div>";
echo "</form>";
// delete from cart
echo "<a href='remove_from_cart.php?id={$id}' class='btn btn-default'>";
echo "Delete";
echo "</a>";
echo "</div>";
echo "<div class='col-md-4'>";
echo "<h4>Rs. " . number_format($sub_total, 2, '.', ',') . "</h4>";
echo "</div>";
echo "</div>";
$item_count += $quantity;
$total+=$sub_total;
}
echo "<div class='col-md-8'></div>";
echo "<div class='col-md-4'>";
echo "<div class='cart-row'>";
echo "<h4 class='m-b-10px'>Total ({$item_count} items)</h4>";
echo "<h4>Rs. " . number_format($total, 2, '.', ',') . "</h4>";
echo "<a href='checkout.php' class='btn btn-success m-b-10px'>";
echo "<span class='glyphicon glyphicon-shopping-cart'></span> Proceed to Checkout";
echo "</a>";
echo "</div>";
echo "</div>";
}else{
echo "<div class='col-md-12'>";
echo "<div class='alert alert-danger'>";
echo "No products found in your cart!";
echo "</div>";
echo "</div>";
}
// layout footer
include 'layout_foot.php';
?>