示例#1
0
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
        $invalid_items = array();
示例#2
0
function get_cart_information()
{
    global $_TABLES, $_CONF;
    require_once $_CONF['path'] . "/plugins/ecommerce/shopping_cart.class.php";
    $c = new shopping_cart($_SESSION['cart']);
    //List each item in cart. Add up sub total.
    $cart_total = 0;
    $arr_items = $c->get_item_array();
    require_once '../shared_functions.php';
    update_quantity($arr_items);
    foreach ($arr_items as $item) {
        $total = $item['price'] * $item['quantity'];
        $cart_contents .= "<tr>\r\n\t\t\t<td>" . $item['name'] . "</td>\r\n\t\t\t<td>\$" . number_format($item['price'], 2) . "</td>\r\n\t\t\t<td align=\"center\">" . $item['quantity'] . "</td>\r\n\t\t\t<td><b>\$" . number_format($total, 2) . "</b></td></tr>";
        $cart_total += $total;
    }
    $cart['total'] = $cart_total;
    $cart['contents'] = $card_contents;
    $cart['items'] = $arr_items;
    return $cart;
}
示例#3
0
        $form_use[$value]->add('Submit', 'submit')->value("Utiliser");
        $form_use[$value]->bound($_POST);
        //construct a array with the product_id
        array_push($tbx_use_index, $value);
    }
    //Arrays for error and confirm message
    $error_buy = array();
    $msg_confirm = array();
    //Treatment for each form
    foreach ($tbx_use_index as $value) {
        //which product user wants to buy
        if ($form_use[$value]->is_valid($_POST)) {
            //add nutrionals aspect to rabbit skill
            use_product($value, $_SESSION['id_nabz']);
            $quantity = display_quantity($value, $_SESSION['id']);
            //Operation on quantity, delete if we you the last in cart or -1 if there is still some in
            if ($quantity - 1 == 0) {
                delete_product_incart($value);
                header("Location: index.php?module=nabz&action=treat&id=" . $_SESSION['id']);
                //Reload page
            } else {
                update_quantity($value);
            }
            $msg_confirm[] = "Action effectuée avec succès, votre lapin se sent déjà mieux.";
        }
        //end of is_valid
    }
    //end of foreach
    include PATH_VIEW . 'view_treat.php';
}
//end user_connected