示例#1
0
$app->on('GET /api/cart', function () {
    $cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : [];
    $this->json($cart);
});
$app->on('POST /api/cart', function () {
    $cart = new Cart();
    $a = $cart->add($this->body);
    $this->json($a);
});
$app->on('PUT /api/cart/:?/:?', function ($productid, $action) {
    $cart = new Cart();
    $a = $cart->update($productid, $action);
    $this->json($a);
});
$app->on('DELETE /api/cart/:?', function ($productid) {
    $cart = new Cart();
    $a = $cart->delete($productid);
    $this->json($a);
});
// CHECKOUT API
// ================
$app->on('GET /api/checkout', function () {
    $checkout = new Checkout();
    $a = $checkout->summary();
    $this->json($a);
});
$app->on('POST /api/checkout', function () {
    $checkout = new Checkout();
    $a = $checkout->validate($this->body);
    $this->json($a);
});