From 93721c5dd5d83f9179610b8f884e751b92370002 Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Sat, 1 Jun 2024 08:23:05 +0400 Subject: [PATCH] rename `deleteOrder` to `cancelOrder` in `Order` model, update implementation to update order status to 'cancelled' instead of deleting, and update `Profile` controller and view to reflect the change --- src/controllers/Profile.php | 2 +- src/models/Order.php | 12 +++--------- src/views/Profile.php | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/controllers/Profile.php b/src/controllers/Profile.php index f6c7892..e518acb 100644 --- a/src/controllers/Profile.php +++ b/src/controllers/Profile.php @@ -145,7 +145,7 @@ public function cancelOrder(): void } // Cancel the order - $order->deleteOrder(); + $order->cancelOrder(); } private function handleProfileEditSubmission(): void diff --git a/src/models/Order.php b/src/models/Order.php index c20cd86..07377be 100644 --- a/src/models/Order.php +++ b/src/models/Order.php @@ -260,21 +260,15 @@ public static function getByID(int $order_id): ?Order } /** - * Deletes the order and associated line items from the database. + * Cancels the order and associated line items from the database. */ - public function deleteOrder(): void + public function cancelOrder(): void { $conn = self::connect(); $conn->beginTransaction(); try { - // Delete line items first - $query = "DELETE FROM order_product WHERE order_id = :order_id"; - $stm = $conn->prepare($query); - $stm->execute(['order_id' => $this->order_id]); - - // Delete the order itself - $query = "DELETE FROM `order` WHERE order_id = :order_id"; + $query = "UPDATE `order` SET status = 'cancelled' WHERE order_id = :order_id"; $stm = $conn->prepare($query); $stm->execute(['order_id' => $this->order_id]); diff --git a/src/views/Profile.php b/src/views/Profile.php index 6051efe..3987139 100644 --- a/src/views/Profile.php +++ b/src/views/Profile.php @@ -100,7 +100,7 @@ $totalPrice = htmlspecialchars(number_format($order->calculateTotalPrice(), 2)); // Determine button states - $cancelDisabled = $order->getStatus()->value === 'completed' ? 'disabled' : ''; + $cancelDisabled = ($order->getStatus()->value === 'completed' || $order->getStatus()->value === 'cancelled') ? 'disabled' : ''; echo <<< EOL