public function orderSimpan(): void { if ($_SERVER['REQUEST_METHOD'] !== 'POST') { redirect(); } // =============================== // Ambil input // =============================== $produkId = (int) ($_POST['produk_id'] ?? 0); $namaPemesan = trim($_POST['nama_pemesan'] ?? ''); $noHp = trim($_POST['no_hp_pemesan'] ?? ''); $ucapan = trim($_POST['ucapan'] ?? ''); $namaPengirim = trim($_POST['nama_pengirim'] ?? ''); $tanggalKirim = $_POST['tanggal_kirim'] ?? null; $jamKirim = $_POST['jam_kirim'] ?? null; $alamatKirim = trim($_POST['alamat_kirim'] ?? ''); $catatan = trim($_POST['catatan'] ?? ''); // =============================== // Validasi sederhana // =============================== if ( !$produkId || !$namaPemesan || !$noHp || !$ucapan || !$tanggalKirim || !$alamatKirim ) { die('Data tidak lengkap.'); } // =============================== // Ambil produk // =============================== require_once APP_PATH . '/models/Produk.php'; $produk = Produk::findById($produkId); if (!$produk) { die('Produk tidak ditemukan.'); } // =============================== // Generate kode order // =============================== $kodeOrder = 'ORD-' . date('YmdHis') . '-' . rand(100, 999); // =============================== // Simpan customer (simple) // =============================== $stmt = db()->prepare(" INSERT INTO customer (nama, no_hp, created_at) VALUES (:nama, :no_hp, NOW()) "); $stmt->execute([ ':nama' => $namaPemesan, ':no_hp' => $noHp, ]); $customerId = db()->lastInsertId(); // =============================== // Hitung total // =============================== $harga = (float) $produk['harga']; $subtotal = $harga; $total = $subtotal; // nanti bisa tambah ongkir/diskon // =============================== // Simpan order // =============================== $stmt = db()->prepare(" INSERT INTO orders ( kode_order, customer_id, tanggal_order, tanggal_kirim, jam_kirim, nama_pemesan, no_hp_pemesan, nama_pengirim, ucapan, alamat_kirim, catatan, subtotal, total_harga, status_order, status_pembayaran, token_tracking, created_at ) VALUES ( :kode_order, :customer_id, NOW(), :tanggal_kirim, :jam_kirim, :nama_pemesan, :no_hp_pemesan, :nama_pengirim, :ucapan, :alamat_kirim, :catatan, :subtotal, :total_harga, 'pending', 'belum_bayar', :token_tracking, NOW() ) "); $tokenTracking = bin2hex(random_bytes(8)); $stmt->execute([ ':kode_order' => $kodeOrder, ':customer_id' => $customerId, ':tanggal_kirim' => $tanggalKirim, ':jam_kirim' => $jamKirim, ':nama_pemesan' => $namaPemesan, ':no_hp_pemesan' => $noHp, ':nama_pengirim' => $namaPengirim, ':ucapan' => $ucapan, ':alamat_kirim' => $alamatKirim, ':catatan' => $catatan, ':subtotal' => $subtotal, ':total_harga' => $total, ':token_tracking' => $tokenTracking, ]); $orderId = db()->lastInsertId(); // =============================== // Simpan order item // =============================== $stmt = db()->prepare(" INSERT INTO order_items ( order_id, produk_id, kode_produk, nama_produk, harga, qty, subtotal, created_at ) VALUES ( :order_id, :produk_id, :kode_produk, :nama_produk, :harga, 1, :subtotal, NOW() ) "); $stmt->execute([ ':order_id' => $orderId, ':produk_id' => $produkId, ':kode_produk' => $produk['kode_produk'], ':nama_produk' => $produk['nama_produk'], ':harga' => $harga, ':subtotal' => $subtotal, ]); // =============================== // Redirect ke sukses // =============================== redirect('order/sukses?kode_order=' . urlencode($kodeOrder)); }500 - Class controller tidak ditemukan: FrontendController