* Date: 2026-5-20 */ if (!defined('ROOT_PATH')) { exit('Access Denied'); } if (!isset($_SESSION['member_id']) || intval($_SESSION['member_id']) <= 0) { header('Location: /member/login.php?redirect=' . urlencode($_SERVER['REQUEST_URI'])); exit; } $pageTitle = '购物车'; $cartItems = $db->fetchAll("SELECT c.*, p.title, p.litpic, p.price AS product_price, p.stock FROM {$db->table('cart')} c LEFT JOIN {$db->table('product')} p ON c.product_id = p.id WHERE c.member_id = ? ORDER BY c.create_time DESC", [intval($_SESSION['member_id'])]); $validItems = []; $totalAmount = 0; foreach ($cartItems as $item) { if (!empty($item['title'])) { $item['subtotal'] = floatval($item['product_price']) * intval($item['quantity']); $totalAmount += $item['subtotal']; $validItems[] = $item; } } $shippingFee = $totalAmount >= 99 ? 0 : 10; $grandTotal = $totalAmount + $shippingFee; $heroImage = !empty($slides[0]['litpic']) ? $slides[0]['litpic'] : ''; require_once __DIR__ . '/../_header.php'; ?> CART 购物车 确认商品信息后可继续进入下单流程。 当前位置:首页 / 购物车 购物车为空,快去选择需要的产品吧。 库存: - + 删除 订单汇总 商品金额 运费 0 ? number_format($shippingFee, 2) : '0.00'); ?> 合计 去结算 function requestCart(action, payload, callback) { var xhr = new XMLHttpRequest(); xhr.open('POST', '/api/cart.php', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function () { if (xhr.status !== 200) { alert('操作失败'); return; } if (typeof callback === 'function') { callback(xhr.responseText); } else { window.location.reload(); } }; xhr.send('action=' + encodeURIComponent(action) + '&' + payload); } function changeQty(cartId, delta) { var input = document.getElementById('qty_' + cartId); if (!input) return; var value = parseInt(input.value, 10) || 1; value = Math.max(1, value + delta); input.value = value; requestCart('update', 'cart_id=' + cartId + '&quantity=' + value); } function removeItem(cartId) { if (!window.confirm('确定删除这个商品吗?')) return; requestCart('remove', 'cart_id=' + cartId); } HTML; require_once __DIR__ . '/../_footer.php'; ?>
确认商品信息后可继续进入下单流程。
库存: