Ejemplo n.º 1
0
<?php

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require 'scripts/init.php';
loadScripts();
$dishId = $_POST["dishId"];
$scm = new ShoppingCartManager();
//$scm->getCartId();
$item = array("dishId" => $dishId, "qty" => "1");
$scm->addItemsToCart($item);
echo json_encode($scm->ToJSON(), JSON_FORCE_OBJECT);
Ejemplo n.º 2
0
                session_unset();
                session_destroy();
                $data = array("status" => "success", "msg" => "Cart cancelled.");
            } else {
                $data = array("status" => "fail", "msg" => "Cart NOT cancelled.");
            }
            break;
        case "checkoutcart":
            // check out the cart
            if (!isset($_SESSION['started'])) {
                $data = array("status" => "fail", "msg" => "There is no cart to check out.");
                echo json_encode($data, JSON_FORCE_OBJECT);
                return;
            }
            // turn the JSON into an array of arrays (true means arrays and not objects)
            $items = json_decode($_POST['items'], true);
            $scm->addItemsToCart($items, $_SESSION['id']);
            $affectedRows = $scm->checkoutCart($_SESSION['id']);
            if ($affectedRows > 0) {
                session_unset();
                session_destroy();
                $data = array("status" => "success", "msg" => "Cart successfully checked out.");
            } else {
                $data = array("status" => "fail", "msg" => "Cart was NOT checked out.");
            }
            break;
    }
} else {
    $data = array("status" => "error", "msg" => "Only POST allowed.");
}
echo json_encode($data, JSON_FORCE_OBJECT);