"Field $field is required"]); exit; } } $customer_name = trim($input['customer_name']); $customer_email = filter_var($input['customer_email'], FILTER_VALIDATE_EMAIL); $customer_address = trim($input['customer_address']); $customer_phone = trim($input['customer_phone']); $cart_items = $input['cart_items']; $shipping_method = $input['shipping_method'] ?? 'posta_slovenije'; if (!$customer_email) { http_response_code(400); echo json_encode(['error' => 'Invalid email address']); exit; } // Calculate totals $subtotal = 0; foreach ($cart_items as $item) { $subtotal += $item['price'] * $item['quantity']; } // Add shipping cost (Pošta Slovenije - 4.90 euro) $shipping_cost = 0; if ($shipping_method === 'posta_slovenije') { $shipping_cost = 4.90; } $total = $subtotal + $shipping_cost; try { $pdo->beginTransaction(); // Create order $stmt = $pdo->prepare("INSERT INTO orders (customer_name, customer_email, customer_address, customer_phone, subtotal, shipping_cost, total_amount, shipping_method, status, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'pending', CURRENT_TIMESTAMP)"); $stmt->execute([ $customer_name, $customer_email, $customer_address, $customer_phone, $subtotal, $shipping_cost, $total, $shipping_method ]); $order_id = $pdo->lastInsertId(); // Add order items foreach ($cart_items as $item) { $stmt = $pdo->prepare("INSERT INTO order_items (order_id, product_id, product_name, quantity, unit_price, total_price) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([ $order_id, $item['id'], $item['name'], $item['quantity'], $item['price'], $item['price'] * $item['quantity'] ]); } $pdo->commit(); echo json_encode([ 'success' => true, 'order_id' => $order_id, 'subtotal' => $subtotal, 'shipping_cost' => $shipping_cost, 'total' => $total, 'message' => 'Naročilo je bilo uspešno oddano!' ]); } catch (Exception $e) { $pdo->rollBack(); http_response_code(500); echo json_encode(['error' => 'Napaka pri oddaji naročila: ' . $e->getMessage()]); } exit; } // Show checkout form ?> Blagajna | Čebelarstvo Cigoj

Blagajna

Vnesite podatke za oddajo naročila

Podatki za dostavo

Povzetek naročila

Izdelki: 0,00 €
Dostava (Pošta Slovenije): 4,90 €
Skupaj: 4,90 €

* Plačilo ob prevzemu (gotovina ali kartica)