diff --git a/admin/orders/index.php b/admin/orders/index.php
new file mode 100644
index 0000000..362f82a
--- /dev/null
+++ b/admin/orders/index.php
@@ -0,0 +1,54 @@
+getConnection();
+
+// Fetch all orders
+$orders_stmt = $conn->query("SELECT * FROM orders ORDER BY created_at DESC");
+$orders = $orders_stmt->fetchAll(PDO::FETCH_ASSOC);
+
+?>
+
+
+
Order Management
+
+
+
+
+ | ID |
+ Status |
+ Total Amount |
+ Customer Details |
+ Date |
+ Actions |
+
+
+
+ 0): ?>
+
+
+ |
+ |
+ $ |
+ |
+ |
+
+ View
+ |
+
+
+
+
+ | No orders found. |
+
+
+
+
+
+
+
diff --git a/admin/orders/view.php b/admin/orders/view.php
new file mode 100644
index 0000000..c5d65d1
--- /dev/null
+++ b/admin/orders/view.php
@@ -0,0 +1,92 @@
+getConnection();
+
+$order_id = $_GET['id'] ?? null;
+
+if (!$order_id) {
+ header('Location: index.php');
+ exit;
+}
+
+// Fetch order details
+$order_stmt = $conn->prepare("SELECT * FROM orders WHERE id = :id");
+$order_stmt->bindParam(':id', $order_id);
+$order_stmt->execute();
+$order = $order_stmt->fetch(PDO::FETCH_ASSOC);
+
+if (!$order) {
+ header('Location: index.php');
+ exit;
+}
+
+// Fetch order items
+$items_stmt = $conn->prepare("SELECT oi.*, p.sku, p.name_translations FROM order_items oi JOIN products p ON oi.product_id = p.id WHERE oi.order_id = :order_id");
+$items_stmt->bindParam(':order_id', $order_id);
+$items_stmt->execute();
+$items = $items_stmt->fetchAll(PDO::FETCH_ASSOC);
+
+?>
+
+
+
+
Order #
+
Back to Orders
+
+
+
+
+
+
Status:
+
Total Amount: $
+
Customer Details:
+
+
Date:
+
+
+
+
+
+
+
+
+
+ | SKU |
+ Product Name |
+ Quantity |
+ Price at Purchase |
+
+
+
+ 0): ?>
+
+
+ |
+
+
+ |
+ |
+ $ |
+
+
+
+
+ | No items found for this order. |
+
+
+
+
+
+
+
+
+
diff --git a/admin/products/edit.php b/admin/products/edit.php
index e3d8086..2ccf77c 100644
--- a/admin/products/edit.php
+++ b/admin/products/edit.php
@@ -1,9 +1,4 @@
getConnection();
-
-$settings = [];
-$result = $connection->query("SELECT * FROM settings");
-while ($row = $result->fetch_assoc()) {
- $settings[$row['key_name']] = $row['key_value'];
-}
+$pdo = db();
+$stmt = $pdo->query("SELECT * FROM settings ORDER BY id DESC LIMIT 1");
+$settings = $stmt->fetch(PDO::FETCH_ASSOC);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stripe_secret_key = $_POST['stripe_secret_key'] ?? '';
$stripe_publishable_key = $_POST['stripe_publishable_key'] ?? '';
- $stmt = $connection->prepare("INSERT INTO settings (key_name, key_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE key_value = VALUES(key_value)");
-
- $key_name_secret = 'stripe_secret_key';
- $stmt->bind_param("ss", $key_name_secret, $stripe_secret_key);
- $stmt->execute();
+ // Check if settings exist
+ $stmt = $pdo->query("SELECT id FROM settings");
+ $exists = $stmt->fetch();
- $key_name_publishable = 'stripe_publishable_key';
- $stmt->bind_param("ss", $key_name_publishable, $stripe_publishable_key);
- $stmt->execute();
+ if ($exists) {
+ $stmt = $pdo->prepare("UPDATE settings SET stripe_publishable_key = ?, stripe_secret_key = ? WHERE id = ?");
+ $stmt->execute([$stripe_publishable_key, $stripe_secret_key, $settings['id']]);
+ } else {
+ $stmt = $pdo->prepare("INSERT INTO settings (stripe_publishable_key, stripe_secret_key) VALUES (?, ?)");
+ $stmt->execute([$stripe_publishable_key, $stripe_secret_key]);
+ }
- $stmt->close();
header('Location: /admin/settings/index.php?success=1');
exit;
}
@@ -56,5 +47,3 @@ include __DIR__ . '/../includes/header.php';
-
-
diff --git a/api/payments/create-payment-intent.php b/api/payments/create-payment-intent.php
index fd18771..5c88088 100644
--- a/api/payments/create-payment-intent.php
+++ b/api/payments/create-payment-intent.php
@@ -13,18 +13,15 @@ if (!file_exists(__DIR__ . '/../../vendor/autoload.php')) {
}
require_once __DIR__ . '/../../vendor/autoload.php';
-require_once __DIR__ . '/../../includes/Database.php';
+require_once __DIR__ . '/../../db/config.php';
// Get DB connection
-$db = Database::getInstance();
-$connection = $db->getConnection();
+$pdo = db();
// Fetch Stripe secret key from settings
-$stripe_secret_key = '';
-$result = $connection->query("SELECT key_value FROM settings WHERE key_name = 'stripe_secret_key'");
-if ($row = $result->fetch_assoc()) {
- $stripe_secret_key = $row['key_value'];
-}
+$stmt = $pdo->query("SELECT stripe_secret_key FROM settings ORDER BY id DESC LIMIT 1");
+$settings = $stmt->fetch(PDO::FETCH_ASSOC);
+$stripe_secret_key = $settings['stripe_secret_key'] ?? '';
if (empty($stripe_secret_key)) {
http_response_code(500);
@@ -56,18 +53,16 @@ if ($product_id === false) {
}
// Fetch product price from the database
-$stmt = $connection->prepare("SELECT price FROM products WHERE id = ?");
-$stmt->bind_param("i", $product_id);
-$stmt->execute();
-$result = $stmt->get_result();
+$stmt = $pdo->prepare("SELECT price FROM products WHERE id = ?");
+$stmt->execute([$product_id]);
+$product = $stmt->fetch(PDO::FETCH_ASSOC);
-if ($result->num_rows === 0) {
+if (!$product) {
http_response_code(404);
echo json_encode(['success' => false, 'message' => 'Product not found.']);
exit;
}
-$product = $result->fetch_assoc();
$price = $product['price'];
// Create a PaymentIntent
diff --git a/checkout.php b/checkout.php
new file mode 100644
index 0000000..402e1db
--- /dev/null
+++ b/checkout.php
@@ -0,0 +1,98 @@
+prepare("SELECT p.id, p.name, p.description, p.price, t.name as translated_name, t.description as translated_description FROM products p LEFT JOIN translations t ON p.id = t.product_id AND t.language_code = 'en' WHERE p.id = ?");
+$stmt->execute([$_GET['product_id']]);
+$product = $stmt->fetch(PDO::FETCH_ASSOC);
+
+if (empty($product)) {
+ header('Location: products.php');
+ exit();
+}
+
+$stmt = $pdo->query("SELECT stripe_publishable_key FROM settings ORDER BY id DESC LIMIT 1");
+$settings = $stmt->fetch(PDO::FETCH_ASSOC);
+$stripe_publishable_key = $settings['stripe_publishable_key'] ?? '';
+
+?>
+
+
+
+
+
+ Checkout
+
+
+
+
+
+
+
+
diff --git a/db/schema.sql b/db/schema.sql
index e5db9ae..5418965 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -1,4 +1,3 @@
-
-- Verras Portal SQL Schema
-- All tables use InnoDB engine for transaction support and foreign key constraints.
@@ -33,24 +32,14 @@ CREATE TABLE IF NOT EXISTS `languages` (
CREATE TABLE IF NOT EXISTS `products` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`sku` VARCHAR(100) NOT NULL UNIQUE,
+ `name_translations` JSON,
+ `description_translations` JSON,
`price` DECIMAL(10, 2) NOT NULL,
`image_url` VARCHAR(2048),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;
--- Table for product translations
-CREATE TABLE IF NOT EXISTS `product_translations` (
- `id` INT AUTO_INCREMENT PRIMARY KEY,
- `product_id` INT NOT NULL,
- `language_code` VARCHAR(10) NOT NULL,
- `name` VARCHAR(255) NOT NULL,
- `description` TEXT,
- UNIQUE KEY `product_lang_unique` (`product_id`, `language_code`),
- FOREIGN KEY (`product_id`) REFERENCES `products`(`id`) ON DELETE CASCADE,
- FOREIGN KEY (`language_code`) REFERENCES `languages`(`code`) ON DELETE CASCADE
-) ENGINE=InnoDB;
-
-- Table for general content (banners, about us, etc.)
CREATE TABLE IF NOT EXISTS `content` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
@@ -98,11 +87,11 @@ CREATE TABLE IF NOT EXISTS `order_items` (
-- Table for application settings (e.g., Stripe keys)
CREATE TABLE IF NOT EXISTS `settings` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
- `key_name` VARCHAR(255) NOT NULL UNIQUE,
- `key_value` TEXT,
+ `stripe_publishable_key` VARCHAR(255),
+ `stripe_secret_key` VARCHAR(255),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
-- Insert default languages
INSERT INTO `languages` (`code`, `name`) VALUES ('en', 'English'), ('es', 'Spanish')
-ON DUPLICATE KEY UPDATE `name`=`name`;
+ON DUPLICATE KEY UPDATE `name`=`name`;
\ No newline at end of file
diff --git a/payment-success.php b/payment-success.php
new file mode 100644
index 0000000..88c8bd1
--- /dev/null
+++ b/payment-success.php
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ Payment Success
+
+
+
+
+
+
Payment Successful!
+
Thank you for your purchase. Your payment has been processed successfully.
+
+
You will receive an email confirmation shortly.
+
+
Continue Shopping
+
+
+
diff --git a/products.php b/products.php
new file mode 100644
index 0000000..61246eb
--- /dev/null
+++ b/products.php
@@ -0,0 +1,35 @@
+query("SELECT p.id, p.name, p.description, p.price, t.name as translated_name, t.description as translated_description FROM products p LEFT JOIN translations t ON p.id = t.product_id AND t.language_code = 'en'");
+
+?>
+
+
+
+
+
+ Products
+
+
+
+
+
+