Skip to content

Commit

Permalink
rename deleteOrder to cancelOrder in Order model, update implem…
Browse files Browse the repository at this point in the history
…entation to update order status to 'cancelled' instead of deleting, and update `Profile` controller and view to reflect the change
  • Loading branch information
Divyeshhhh committed Jun 1, 2024
1 parent 401db2b commit 93721c5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/controllers/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function cancelOrder(): void
}

// Cancel the order
$order->deleteOrder();
$order->cancelOrder();
}

private function handleProfileEditSubmission(): void
Expand Down
12 changes: 3 additions & 9 deletions src/models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion src/views/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
<tr>
Expand Down

0 comments on commit 93721c5

Please sign in to comment.