Beispiel #1
0
function is_item_added($user_id, $item_id)
{
    global $db;
    $cart_id = get_user_cart_id($user_id);
    $query = "SELECT * FROM cart_item";
    $query .= " WHERE cart_id = {$cart_id}";
    $query .= " AND item_id = {$item_id}";
    $results = mysqli_query($db, $query);
    $result = mysqli_fetch_row($results);
    if (empty($result)) {
        return false;
    }
    mysqli_free_result($results);
    return true;
}
Beispiel #2
0
<?php

if (!isset($_SESSION['id'])) {
    // if not logged in , go register
    redirect_to("register.php");
}
$cart_id = get_user_cart_id($_SESSION['id']);
// get the user cart
if (isset($_POST['update'])) {
    $invalid_items = array();
    $cart_items = $_POST;
    foreach ($cart_items as $key => $quantity) {
        if ($key === "update") {
            break;
        }
        // reached last index (avoid breaking the app :D)
        update_quantity($key, $quantity);
    }
    // clear the cart from invalid cart items with SORRY message (NOT IMPLEMENTED)
}
if (isset($_POST['checkout'])) {
    $total_price = calculate_total_price($cart_id);
    $user_credit = get_user_credit($_SESSION['id']);
    if ($total_price > $user_credit) {
        echo "Please Recharge , Credit not enough";
        // error message (out of credit)
    } else {
        //get orders
        $results = get_all_orders($cart_id);
        //process each one
        //invalid item array