$item) { // Ensure item has required data if (!isset($item['price'], $item['quantity'], $item['name'], $item['image_url'])) { // Skip malformed items continue; } $item_total = $item['price'] * $item['quantity']; $total_price += $item_total; // Store details for display $product_details[] = [ 'id' => $item['product_id'], 'name' => $item['name'], 'price' => $item['price'], 'image_url' => $item['image_url'], 'quantity' => $item['quantity'], 'color' => $item['color'] ?? '', // Handle case where color might not be set 'total' => $item_total ]; } // 3. If after all checks, product_details is empty (e.g. invalid items in cart), redirect. if (empty($product_details)) { // Clear the invalid cart and redirect unset($_SESSION['cart']); header('Location: shop.php'); exit(); } // 4. Fetch user data if logged in $user_id = $_SESSION['user_id'] ?? null; $user = []; $address = []; if ($user_id) { try { $pdo = db(); $user_stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); $user_stmt->execute([$user_id]); $user = $user_stmt->fetch(PDO::FETCH_ASSOC) ?: []; $address_stmt = $pdo->prepare("SELECT * FROM user_addresses WHERE user_id = ? ORDER BY id DESC LIMIT 1"); $address_stmt->execute([$user_id]); $address = $address_stmt->fetch(PDO::FETCH_ASSOC) ?: []; } catch (PDOException $e) { error_log("Checkout user fetch error: " . $e->getMessage()); // Do not block the page, guest checkout is still possible } } $shipping_cost = 50000; $grand_total = $total_price + $shipping_cost; ?>

تکمیل سفارش و پرداخت

اطلاعات خود را برای ارسال سفارش وارد کنید.

جزئیات صورتحساب

    '; foreach ($_SESSION['checkout_errors'] as $error) { echo '
  • ' . htmlspecialchars($error) . '
  • '; } echo '
'; // Unset the session variable so it doesn't show again on refresh unset($_SESSION['checkout_errors']); } ?>
اطلاعات تماس
آدرس جهت ارسال

خلاصه سفارش شما

  • (x) T
جمع کل T
هزینه ارسال T
مبلغ قابل پرداخت T