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(); echo "cart emptied!"; header("location:./shop_cart.php"); } } }
<?php include "includes/db.php"; include "includes/functions.php"; if ($_REQUEST['command'] == 'delete' && $_REQUEST['pid'] > 0) { remove_product($_REQUEST['pid']); //remove_cart(); } else { if ($_REQUEST['command'] == 'clear') { unset($_SESSION['cart']); } else { if ($_REQUEST['command'] == 'update') { $max = count($_SESSION['cart']); for ($i = 0; $i < $max; $i++) { $pid = $_SESSION['cart'][$i]['productid']; $q = intval($_REQUEST['product' . $pid]); if ($q > 0 && $q <= 999) { $_SESSION['cart'][$i]['qty'] = $q; } else { $msg = 'Some proudcts not updated!, quantity must be a number between 1 and 999'; } } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Shopping Cart</title>
*/ session_start(); /* - Require các file cần thiết */ require_once '../configs/db.php'; require_once '../configs/connectdb.php'; require_once '../configs/site.php'; require_once '../functions/common.php'; require_once '../functions/product.php'; require_once '../functions/cart.php'; /* - Xử lý các lệnh cập nhật, xóa */ if (isset($_POST['remove']) && $_POST['remove'] == "Xóa" && $_POST['pid'] > 0) { remove_product($_POST['pid']); } else { if (isset($_POST['clear']) && $_POST['clear'] == "Xóa giỏ") { unset($_SESSION['cart']); } else { if (isset($_POST['update']) && $_POST['update'] == "Cập nhật") { $max = count($_SESSION['cart']); for ($i = 0; $i < $max; $i++) { $pid = $_SESSION['cart'][$i]['product_id']; $q = intval($_POST['product' . $pid]); if ($q > 0 && $q <= 50) { $_SESSION['cart'][$i]['quantity'] = $q; } else { $msg = 'Một vài sản phẩm không được cập nhật, số lượng phải nằm từ 1 đến 50'; } }
function ProductsErase() { global $_POST; $ProdID = olc_db_prepare_input($_POST['prodid']); if (isset($ProdID)) { // ProductsToCategieries loeschen bei denen die products_id = ... ist $res1 = olc_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . $ProdID . "'"); // Product loeschen remove_product($ProdID); $code = 0; $message = 'OK'; } else { $code = 99; $message = 'FAILED'; } print_xml_status(0, $_POST['action'], 'OK', '', 'SQL_RES1', $res1); }
<?php require_once __DIR__ . '/lib/functions.php'; //die; $res = remove_product(); if ($res) { $message = 'Продукт с id:' . $_GET['id'] . ' успешно удален'; $success = true; } else { $message = 'Не удалось удалить продукт id:' . $_GET['id']; $success = false; } echo json_encode(array('success' => $success, 'message' => $message));
</script> </head> <style type="text/css"> #CapNhatGioHang #frm { width: 585px; } </style> <body> <?php //include("dbcon.php"); include "cart.php"; $msg = ""; $_SESSION['muahangxong'] = ""; if (@$_REQUEST['command'] == 'delete') { remove_product($_REQUEST['idSP']); } if (@$_REQUEST['command'] == 'clear') { unset($_SESSION['somathang']); } if (@$_REQUEST['command'] == 'update') { $max = count($_SESSION['somathang']); for ($i = 0; $i < $max; $i++) { $idSP = $_SESSION['somathang'][$i]['idSP']; $SoLuong = intval($_REQUEST['SoLuong_' . $idSP]); if ($SoLuong > 0 && SoLuong <= 999) { $_SESSION['somathang'][$i]['SoLuong'] = $SoLuong; } else { $msg = 'So luong phai tu 1 den 999'; } }