-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.php
More file actions
105 lines (94 loc) · 2.35 KB
/
checkout.php
File metadata and controls
105 lines (94 loc) · 2.35 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
<?php
/**
* Created by PhpStorm.
* User: Charles
* Date: 11/18/13
* Time: 3:13 PM
*/
include_once 'header2.php';
if ($loggedin && $toyCart->uniqueToys() >=1 && isset($_SESSION['street']))
{
$street = $_SESSION['street'];
$city = $_SESSION['city'];
$zip = $_SESSION['zip'];
$state = $_SESSION['state'];
$date = getdate();
$d = $date[0];
echo <<<EOD
<h1 align="center">Review your order</h1>
<h5>
<div class="container">
<div class="well">
<b>Shipping address</b><br>
$street, $city,<br>
$state, $zip<br>
</div>
</div>
<br>
<div class="container">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading"><b>Shopping Cart</b></div>
<!-- Table -->
<table class="table">
<tr>
<td>#</td>
<td>Toy</td>
<td>Price</td>
<td>Quantity</td>
</tr>
EOD;
$n = 0;
$toy = $toyCart->getToyName();
$quantity = $toyCart->getToyQuantity();
$price = $toyCart->getToyPrice();
$discount = $toyCart->getToyDiscount();
$weight = $toyCart->getWeight();
$finalPrice = 0;
$subtotal = 0;
$totalLBS = 0;
for ($j = 0; $j < $toyCart->uniqueToys(); $j++)
{
$n++;
$finalPrice = ($price[$j] * $discount[$j]);
$subtotal += ($finalPrice * $quantity[$j]);
$formatted = number_format($finalPrice, 2, '.', ',');
$totalLBS += $weight[$j];
echo <<<EOD
<tr>
<td>$n</td>
<td>$toy[$j]</td>
<td>\$$formatted</td>
<td>$quantity[$j]</td>
</tr>
EOD;
}
echo "</table></div></div><br>";
$subtotal2 = number_format($subtotal, 2, '.', ',');
$shippingCost = number_format((5 + ($totalLBS * 0.75)), 2, '.', ','); // initial rate of $5 + $0.75/lb of weight
$formatted2 = number_format(($subtotal + $shippingCost), 2, '.', ',');
echo <<<EOD
<div class="container">
<div class="well">
<b>Order summary</b><br>
Items: $$subtotal2<br>
Shipping & handling: $$shippingCost<br>
<font color="red"><b>Order total = \$$formatted2</b></font></div>
</div>
</div>
EOD;
// checkout button
echo <<<_END
<div class="container">
<form method='post' action='processing.php?user=$user'>
<input type="hidden" name='date' value='$d'>
<input type='submit' value='Place order' class="btn btn-warning">
</form>
</div>
_END;
}
else
{
echo "<h1 align=center>Access denied</h1>";
}
include_once 'footer.php';