예제 #1
0
<?php

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require 'scripts/init.php';
loadScripts();
$scm = new ShoppingCartManager();
$k = $scm->checkoutCart();
//$scm->setCartId();
$username = $scm->getShoppingCartOwner();
if ($k > 0) {
    $data = array('msg' => 'Cart checked out', 'cartOwner' => $username);
} else {
    $data = array('msg' => 'Cart has not been updated');
}
//unset($_SESSION['cartId']);
echo json_encode($data, JSON_FORCE_OBJECT);
예제 #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);
예제 #3
0
파일: cart.php 프로젝트: siobhan-walsh/kiki
                $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);
            $total = $_POST['total'];
            $scm->addItemsToCart($items, $_SESSION['id']);
            $affectRows = $scm->checkoutCart($_SESSION['id'], $total);
            $pm->updateProductStock($items);
            if ($affectRows > 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);