Item |
Quantity |
Price |
Subtotal |
';
// Display the products:
// Need the utility functions:
include('./includes/product_functions.inc.php');
// Initialize the total:
$total = 0;
// For removing problematic items:
$remove = array();
// Fetch each product:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
// Check the stock status:
if ($row['stock'] < $row['quantity']) {
echo 'There are only ' . $row['stock'] . ' left in stock of the ' . $row['name'] . '. This item has been removed from your cart and placed in your wish list. |
';
$remove[$row['sku']] = $row['quantity'];
} else {
// Get the correct price:
$price = get_just_price($row['price'], $row['sale_price']);
// Calculate the subtotal:
$subtotal = $price * $row['quantity'];
// Print out a table row:
echo '' . $row['category'] . '::' . $row['name'] . ' |
' . $row['quantity'] . ' |
$' . $price . ' |
$' . number_format($subtotal, 2) . ' |
';
// Add the subtotal to the total:
$total += $subtotal;
}
} // End of WHILE loop.
// Add the shipping:
$shipping = get_shipping($total);
$total += $shipping;
echo '
| Shipping & Handling |
$' . number_format($shipping, 2) . ' |
';
// Store the shipping in the session:
$_SESSION['shipping'] = $shipping;
// Display the total:
echo '
| Total |
$' . number_format($total, 2) . ' |
|
';
// Remove any problematic items:
if (!empty($remove)) {
// Clear the results:
mysqli_next_result($dbc);
// Loop through the array:
foreach ($remove as $sku => $qty) {
list($sp_type, $pid) = parse_sku($sku);
// Move it to the wish list:
$r = mysqli_multi_query($dbc, "CALL add_to_wish_list('$uid', '$sp_type', $pid, $qty);CALL remove_from_cart('$uid', '$sp_type', $pid)");
} // End of FOREACH loop.
} // End of $remove IF.
echo '
';
echo BOX_END;