feat: initial foundation for collaborative canteen ordering system in vanilla PHP

This commit is contained in:
2026-08-27 17:29:13 +07:00
commit 5effce30cb
52 changed files with 4915 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Models;
use App\Core\Database\Database;
use PDO;
class OrderItem
{
public static function getByOrderId(int $orderId): array
{
$db = Database::getConnection();
$stmt = $db->prepare("
SELECT oi.*, p.sku, p.category
FROM order_items oi
LEFT JOIN products p ON oi.product_id = p.id
WHERE oi.order_id = ?
ORDER BY oi.id ASC
");
$stmt->execute([$orderId]);
return $stmt->fetchAll();
}
public static function create(array $data): int
{
$db = Database::getConnection();
$stmt = $db->prepare("
INSERT INTO order_items (order_id, product_id, product_name, quantity, unit_price, total_price)
VALUES (:order_id, :product_id, :product_name, :quantity, :unit_price, :total_price)
");
$stmt->execute([
':order_id' => $data['order_id'],
':product_id' => $data['product_id'],
':product_name' => $data['product_name'],
':quantity' => $data['quantity'],
':unit_price' => $data['unit_price'],
':total_price' => $data['total_price'],
]);
return (int)$db->lastInsertId();
}
}