35289-vm/app/Models/Order.php
Flatlogic Bot 163c483584 atual
2025-10-28 01:29:21 +00:00

27 lines
941 B
PHP

<?php
require_once __DIR__ . '/../../db/config.php';
class Order {
public static function create($customerName, $customerEmail, $total) {
$pdo = db();
$sql = "INSERT INTO orders (customer_name, customer_email, total) VALUES (?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$customerName, $customerEmail, $total]);
return $pdo->lastInsertId();
}
public static function createOrderItem($orderId, $productId, $quantity, $price) {
$pdo = db();
$sql = "INSERT INTO order_items (order_id, product_id, quantity, price) VALUES (?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$orderId, $productId, $quantity, $price]);
}
public static function getAll() {
$pdo = db();
$sql = "SELECT * FROM orders ORDER BY created_at DESC";
$stmt = $pdo->query($sql);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
?>