Esempio n. 1
0
function showCartTable($cart, $readonly = FALSE)
{
    if (!is_array($cart)) {
        echo "Empty cart<br>";
        return;
    }
    echo "<table border='0' width='100%'>\r\n\t\t\t<tr><td bgcolor='black'>Item</td>\r\n\t\t\t<td bgcolor='black'>Price</td>\r\n\t\t\t<td bgcolor='black'>Quantity</td>\r\n\t\t\t<td bgcolor='black' align='right'>Total</td></tr>";
    if (!$readonly) {
        echo "<form action='cart.php' method='post' id='editqty'>";
    }
    foreach ($cart as $pid => $qty) {
        $product = getProductInfo($pid);
        echo "<tr>";
        echo "<td><a href='viewitem.php?p=" . $pid . "'>" . $product['productname'] . "</a></td>";
        echo "<td>\$" . $product['price'] . "</td>";
        if ($readonly) {
            echo "<td>" . $qty . "</td>";
        } else {
            echo "<td><input type='text' name='" . $pid . "' value='" . $qty . "' size='2'></td>";
        }
        echo "<td align='right'>\$" . number_format($qty * $product['price'], 2) . "</td>";
        if (!$readonly) {
            echo "<td align='right'><a href='cart.php?remove=" . $pid . "'>Remove</a></td>";
        } else {
            echo "";
        }
        echo "</tr>";
    }
    echo "<tr>";
    echo "<td colspan='2'>&nbsp;</td>\r\n\t\t\t<td><b>" . countItems($cart) . "</b></td>\r\n\t\t\t<td align='right'><b>\$" . number_format(calculateTotal($cart), 2) . "</b></td>";
    echo "</tr>";
    if (!$readonly) {
        echo "<tr>";
        echo "<td colspan='2'>&nbsp;</td>\r\n\t\t\t<td align='center'><input type='submit' name='edit' value='Update' /></td>\r\n\t\t\t<td>&nbsp;</td>";
        echo "</tr></form>";
    }
    echo "</table>";
}
/**
* This function displays a form of an order purchased based on the $itemsPuchased parameter 
* which is an array storing the items the customer purchased and the quantity of each of those
* items the customer purchased, and the $itemsAvailable parameter which is an array storing Item
* objects that hold the price of each of those items. The form displays each item purchased, the
* quantity purchased, the price of the item, and the item total.  It also displays the subtotal,
* tax, and the total cost of the order.  It displays it in a nicely formatted table.
*
* @param Array $itemsPurchased An array storing items purchased as key and quantity purchased as
*                               its value
* @param Array $itemsAvailable An array of Item objects that hold the price of each item
* @return String  $myReturn    A string representation of the form of items purchased and cost of
*                               each item, subtotal cost, tax, and the total cost of the purchase.
* @todo none
**/
function displayOrder($itemsPurchased, $itemsAvailable)
{
    //create a string to hold form that holds purchased order form
    $myReturn = '';
    //use the calculateTotal() function to calculate the total of the order based on items user selected
    $total = calculateTotal($itemsPurchased, $itemsAvailable);
    //add table tags to format form table, with quanity, item, price, and item total columns
    $myReturn .= '
    <table border="1" style="width:50%">
    <tr>
    <td>Quantity</td>
    <td>Item</td>
    <td>Price</td>
    <td>Item Total</td>
    </tr>';
    //loop through the itemsPurchased array to get the items the user purchased and quantity of each item they want to purchase
    foreach ($itemsPurchased as $item => $quantity) {
        //loop through itemsAvailable array which is Item array that holds the items available that dynamically get added to form
        foreach ($itemsAvailable as $itm) {
            //if the item name in itemsAvailable array matches the item the user selected
            if ($itm->name == $item) {
                //grabe the item object from the itemsAvailable array
                $itemObject = $itm;
            }
            //find the price of the array by selecting the price property of the item and store in price variable
            $price = $itemObject->price;
        }
        //in $_POST[] even if user didn't pick, empty string.  This makes a 0 in quantity for better
        //output formatting in output table
        if ($quantity == "") {
            //display a 0 if user didn't enter a quantity for better output formatting
            $quantity = 0;
        }
        //create a subTotal array to store subtotal of each item (price * quantity)
        $subTotalArray[] = $price * $quantity;
        //add quantity user selected, item name, price of each item, and subtotal of each item formatted to 2 decimal places
        //to the purchased order form
        $myReturn .= '<tr><td>' . $quantity . '</td>
    <td>' . $item . '</td>
    <td>' . number_format($price, 2) . '</td>
    <td>$' . number_format($price * $quantity, 2) . '</td>
    
    </tr>';
    }
    //create a subTotal variable to store the subTotal of the whole purchase, not just each item as subTotal did above
    $subTotal = 0;
    //loop through subTotalArray that stores the subTotal of each item
    foreach ($subTotalArray as $itemTotal) {
        //add the subtotal of each item to the subTotal of the entire order
        $subTotal += $itemTotal;
    }
    //calculate tax of the subTotal as 9.5% tax rate
    $tax = $subTotal * 0.095;
    //add subTotal, tax, and total (subTotal plus tax) to the form columns
    $myReturn .= '<tr><td></td><td></td><td>Subtotal</td><td>$' . number_format($subTotal, 2) . '</td></tr>
                <tr><td></td><td></td><td>Tax</td><td>$' . number_format($tax, 2) . '</td></tr>
        <tr><td></td><td></td><td>Total</td><td>$' . number_format($total + $tax, 2) . '</td></tr></table>';
    //return the purchased order form string
    return $myReturn;
}
function getShoppingCart()
{
    //Function creates the display for the cart
    //If the cart exists then follow on
    if (cartExists()) {
        //Check if there are any products in the cart by counting the array keys
        if (count($_SESSION['paypalCart']) > 0) {
            //The table header html
            $html = '
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<th>Product</th>
					<th>Price</th>
					<th>Qty</th>
					<th></th>
				</tr>
			';
            $count = 1;
            //Loop through the items in the paypal cart
            foreach ($_SESSION['paypalCart'] as $product) {
                $html .= '
				<tr>
					<td>' . $product['name'] . '</td>
					<td>&euro;' . number_format($product['price'], 2) . '</td>
					<td>' . $product['qty'] . '</td>
					<td><a href="addToCart.php?ID=' . $product['ID'] . '">Add</a><a href="removeFromCart.php?ID=' . $product['ID'] . '">Remove</a></td>
					<input type="hidden" name="amount_' . $count . '" value="' . $product['price'] . '" />
					<input type="hidden" name="quantity_' . $count . '" value="' . $product['qty'] . '" />
					<input type="hidden" name="tax_rate_' . $count . '" value="' . TAX . '" />
					<input type="hidden" name="item_name_' . $count . '" value="' . stripslashes($product['name']) . '" />
					<input type="hidden" name="item_number_' . $count . '" value="' . $product['ID'] . '" />
				</tr>
				';
                $count++;
            }
            //HTML for the subrows such as the subtotal, tax and total
            $html .= '
				<tr class="empty">
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td></td>
					<td class="bold">Subtotal</td>
					<td>' . calculateSubtotal() . '</td>
				</tr>
				<tr>
					<td></td>
					<td></td>
					<td class="bold">TAX @ ' . TAX . '%</td>
					<td>' . calculateTax() . '</td>
				</tr>
				<tr>
					<td></td>
					<td></td>
					<td class="bold">Total</td>
					<td>' . calculateTotal() . '</td>
				</tr>
			
			</table>
			
			<input type="submit" name="submit" id="submit" value="Checkout with PayPal" />
			
			';
            echo $html;
        } else {
            //If there are no products then print out a message saying there are no products
            echo '<p>There are currently no products in your cart.</p>';
        }
    } else {
        //If there are no products then print out a message saying there are no products
        echo '<p>There are currently no products in your cart.</p>';
    }
}
Esempio n. 4
0
    die;
}
if (isset($_SESSION['errmsg'])) {
    echo $_SESSION['errmsg'] . "<br>";
    unset($_SESSION['errmsg']);
}
echo "<p><h2>Thank you for shopping with us!<br>Your order ID is: " . $orderid . "</h2></p>";
showCartTable($_SESSION['cart'], TRUE);
// Display read only version of shopping cart table
?>
	
	
<table border="0" width="100%" >
<tr><td align="left">Tax</td>
<td align="right"> <?php 
echo number_format(calculateTax(calculateTotal($_SESSION['cart'])), 2);
?>
</td></tr>
<tr><td align="left">Shipping</td>
<td align="right"> <?php 
echo number_format($_POST['shipping'], 2);
?>
</td></tr>
<tr><td bgcolor="black" align="left">TOTAL:</td>
<td bgcolor="black" align="right"><b>$ <?php 
echo number_format($_POST['total'], 2);
?>
</b></td>
</tr>
</table>
Esempio n. 5
0
?>
		
<table border="0" width="100%" >
<tr><td align="left">Tax</td>
<td align="right"> <?php 
echo number_format(calculateTax(calculateTotal($_SESSION['cart'])), 2);
?>
</td></tr>
<tr><td align="left">Shipping</td>
<td align="right"> <?php 
echo number_format(calculateShipping($_POST['shipping']), 2);
?>
</td></tr>
<tr><td bgcolor="black" align="left">TOTAL:</td>
<?php 
$total = calculateShipping($_POST['shipping']) + calculateTotal($_SESSION['cart']) + calculateTax(calculateTotal($_SESSION['cart']));
?>
<td bgcolor="black" align="right"><b>$ <?php 
echo number_format($total, 2);
?>
</b></td>
</tr>
</table>
<form action="receipt.php" method="post">

<!-- Messy way of keeping everything from the checkout form -->
<input name="addr" type="hidden" value="<?php 
echo $_POST["addr"];
?>
" />
<input name="city" type="hidden" value="<?php 
Esempio n. 6
0
    }
    return " ";
}
function personalInformation($arr)
{
    extract($arr);
    global $summary;
    $summary .= "<h3>Address</h3>";
    $summary .= "<address class='text-left'>" . $inputStreet . "<br>" . $inputCity . ", " . $selectProvince . " " . $inputPostalCode . "<br>" . "<abbr title='Phone'>P:</abbr>" . $inputPhone . "</address> ";
    $summary .= "<address class='text-left'>" . "<strong>" . $inputName . "</strong><br>" . "<a href='mailto:#'>" . $inputEmail . "</a>" . "</address>";
}
if (isset($_POST['buttonOrder'])) {
    $errorMsg = validateFeedbackForm($_POST);
    global $summary;
    if (!isset($errorMsg)) {
        calculateTotal();
        //get the file
        $file = 'receipt.txt';
        // Write the contents to the file
        file_put_contents($file, $summary);
    }
}
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Conestoga Pizzeria - Assignment 1</title>
		<link type="text/css" rel="stylesheet" href="css/style.css"/> 
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
		<script src="js/validation.js"></script>