Ejemplo n.º 1
0
$quantity = filter_input(INPUT_POST, 'quantity');
//start cart session
if ($action == "start_cart") {
    //start the cart
    start_cart_session();
    echo "cart started!";
} else {
    if ($action == "end_cart") {
        end_cart_session();
        echo "cart ended!";
    } else {
        if ($action == "view_cart") {
            view_cart();
        } else {
            if ($action == "add_product") {
                add_product_to_cart($product_id, $quantity);
                echo "added product to cart!";
                header("location:./shop_cart.php");
            } else {
                if ($action == "remove_product") {
                    remove_product($product_id);
                    echo "Remove product from cart";
                    header("location:./shop_cart.php");
                } else {
                    if ($action == "update_quantity") {
                        update_product_cart($product_id, $quantity);
                        echo "Update product quantity in cart";
                        header("location:./shop_cart.php");
                    } else {
                        if ($action == "empty_cart") {
                            clear_cart();
Ejemplo n.º 2
0
<?php

require __DIR__ . '/src/bootstrap.php';
if (array_key_exists('clean_cart', $_GET)) {
    clean_cart();
    header('Location: /index.php');
    die;
}
if (array_key_exists('add_product_id', $_GET)) {
    add_product_to_cart($_GET['add_product_id']);
    header('Location: /cart.php');
    die;
}
if (array_key_exists('remove_product_id', $_GET)) {
    remove_product_from_cart($_GET['remove_product_id']);
    header('Location: /cart.php');
    die;
}
$cart_products = get_cart_products();
echo render_store_template('cart', ['cart_products' => $cart_products, 'cart_products_count' => get_cart_products_count(), 'cart_total_amount' => get_cart_total_amount()]);