diff --git a/header.php b/header.php
index a5b2ccd1..309d5e3b 100644
--- a/header.php
+++ b/header.php
@@ -19,6 +19,12 @@ session_start();
Enter delivery address
+
+
+
Order from Majuro's best
+
+
All Cuisines
query("SELECT DISTINCT cuisine FROM restaurants ORDER BY cuisine");
$cuisines = $cuisine_stmt->fetchAll(PDO::FETCH_COLUMN);
+ $search_param = isset($_GET['search']) ? '&search=' . urlencode($_GET['search']) : '';
+ foreach ($cuisines as $cuisine):
?>
-
-
-
-
+
= htmlspecialchars($cuisine) ?>
+
+
diff --git a/migrations/20251015_add_status_to_orders.sql b/migrations/20251015_add_status_to_orders.sql
new file mode 100644
index 00000000..bb88dc5a
--- /dev/null
+++ b/migrations/20251015_add_status_to_orders.sql
@@ -0,0 +1 @@
+ALTER TABLE orders ADD COLUMN status VARCHAR(50) NOT NULL DEFAULT 'Pending';
\ No newline at end of file
diff --git a/migrations/20251015_create_coupons_table.sql b/migrations/20251015_create_coupons_table.sql
new file mode 100644
index 00000000..1aaf8900
--- /dev/null
+++ b/migrations/20251015_create_coupons_table.sql
@@ -0,0 +1,7 @@
+CREATE TABLE IF NOT EXISTS "coupons" (
+ "id" SERIAL PRIMARY KEY,
+ "code" VARCHAR(255) NOT NULL UNIQUE,
+ "discount_percentage" DECIMAL(5, 2) NOT NULL,
+ "is_active" BOOLEAN NOT NULL DEFAULT TRUE,
+ "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
\ No newline at end of file
diff --git a/migrations/20251015_update_orders_for_coupons.sql b/migrations/20251015_update_orders_for_coupons.sql
new file mode 100644
index 00000000..e4ac6b68
--- /dev/null
+++ b/migrations/20251015_update_orders_for_coupons.sql
@@ -0,0 +1,4 @@
+ALTER TABLE "orders"
+ADD COLUMN "coupon_id" INT NULL,
+ADD COLUMN "discount_amount" DECIMAL(10, 2) DEFAULT 0.00,
+ADD CONSTRAINT "fk_coupon" FOREIGN KEY ("coupon_id") REFERENCES "coupons"("id");
diff --git a/payment-success.php b/payment-success.php
index e8f05cb8..de27beff 100644
--- a/payment-success.php
+++ b/payment-success.php
@@ -34,14 +34,9 @@ try {
exit();
}
- $total_price = 0;
- $restaurant_id = null;
- foreach ($cart_items as $item) {
- $total_price += $item['price'] * $item['quantity'];
- $restaurant_id = $item['restaurant_id']; // Assuming all items in cart are from the same restaurant
- }
- $delivery_fee = 5.00;
- $total_price += $delivery_fee;
+ $total_price = $_SESSION['total_price'] ?? 0;
+ $discount_amount = $_SESSION['discount_amount'] ?? 0;
+ $coupon_id = $_SESSION['coupon']['id'] ?? null;
// Get delivery details stored in cart
$delivery_name = $cart_items[0]['delivery_name'];
@@ -49,8 +44,8 @@ try {
$delivery_phone = $cart_items[0]['delivery_phone'];
// Create order
- $stmt = $pdo->prepare("INSERT INTO orders (user_id, restaurant_id, total_price, status, stripe_session_id, delivery_name, delivery_address, delivery_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- $stmt->execute([$user_id, $restaurant_id, $total_price, 'paid', $stripe_session_id, $delivery_name, $delivery_address, $delivery_phone]);
+ $stmt = $pdo->prepare("INSERT INTO orders (user_id, restaurant_id, total_price, status, stripe_session_id, delivery_name, delivery_address, delivery_phone, coupon_id, discount_amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ $stmt->execute([$user_id, $restaurant_id, $total_price, 'paid', $stripe_session_id, $delivery_name, $delivery_address, $delivery_phone, $coupon_id, $discount_amount]);
$order_id = $pdo->lastInsertId();
// Insert order items
diff --git a/paypal-capture.php b/paypal-capture.php
index 79be9c25..1d54f11d 100644
--- a/paypal-capture.php
+++ b/paypal-capture.php
@@ -66,22 +66,21 @@ if (isset($details->status) && $details->status == 'COMPLETED') {
exit();
}
- $total_price = 0;
+ $total_price = $_SESSION['total_price'] ?? 0;
+ $discount_amount = $_SESSION['discount_amount'] ?? 0;
+ $coupon_id = $_SESSION['coupon']['id'] ?? null;
$restaurant_id = null;
foreach ($cart_items as $item) {
- $total_price += $item['price'] * $item['quantity'];
$restaurant_id = $item['restaurant_id'];
}
- $delivery_fee = 5.00;
- $total_price += $delivery_fee;
$delivery_name = $_POST['name'];
$delivery_address = $_POST['address'];
$delivery_phone = $_POST['phone'];
// Create order
- $stmt = $pdo->prepare("INSERT INTO orders (user_id, restaurant_id, total_price, status, stripe_session_id, delivery_name, delivery_address, delivery_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- $stmt->execute([$user_id, $restaurant_id, $total_price, 'paid', $orderID, $delivery_name, $delivery_address, $delivery_phone]);
+ $stmt = $pdo->prepare("INSERT INTO orders (user_id, restaurant_id, total_price, status, stripe_session_id, delivery_name, delivery_address, delivery_phone, coupon_id, discount_amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ $stmt->execute([$user_id, $restaurant_id, $total_price, 'paid', $orderID, $delivery_name, $delivery_address, $delivery_phone, $coupon_id, $discount_amount]);
$order_id = $pdo->lastInsertId();
// Insert order items
diff --git a/remove_coupon.php b/remove_coupon.php
new file mode 100644
index 00000000..922552a9
--- /dev/null
+++ b/remove_coupon.php
@@ -0,0 +1,9 @@
+prepare(
+ 'SELECT r.*, COALESCE(AVG(ra.rating), 0) as rating, COUNT(ra.id) as rating_count '
+ . 'FROM restaurants r LEFT JOIN ratings ra ON r.id = ra.restaurant_id '
+ . 'WHERE r.name LIKE ? OR r.cuisine LIKE ? GROUP BY r.id'
+ );
+ $stmt->execute(['%' . $query . '%', '%' . $query . '%']);
+ $restaurants = $stmt->fetchAll();
+} else {
+ $restaurants = [];
+}
+?>
+
+
+ Search Results for ""
+
+
+
+
No restaurants found.
+
+
+
+
+
+
+
+
+