require_once 'bootstrap.php'; // Check if user is logged in if (!isset($_SESSION['user_id'])) { header('Location: login.php'); exit(); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf(); } // Get cart items $userId = $_SESSION['user_id']; $cartItems = getCartItems($userId); $total = calculateTotalCartPrice($cartItems); $finalTotal = calculateFinalTotal($total); // Handle cart updates if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['update'])) { foreach ($_POST['quantity'] as $productId => $quantity) { if ($quantity > 0) { addToCart($userId, $productId, $quantity); } else { removeFromCart($userId, $productId); } } header('Location: cart.php'); exit(); } elseif (isset($_POST['checkout'])) { $orderId = createOrder($userId, $cartItems); if ($orderId) { header('Location: order.php?id=' . $orderId); exit(); } else { $error = "حدث خطأ أثناء إنشاء الطلب"; } } } // Get shipping methods $shippingMethods = getShippingMethods(); // Get payment methods $paymentMethods = getPaymentMethods(); // Get return policy $returnPolicy = getReturnPolicy(); // Get FAQ $faq = getFAQs(); // Get contact info $contactInfo = getContactInfo(); // Get social media links $socialMediaLinks = getSocialMediaLinks(); // Get currency info $currency = getCurrency(); $currencySymbol = getCurrencySymbol(); ?>
سلة التسوق فارغة
تصفح المنتجات