From f951c15dab3c987eae0dd0dfac4cbb796343e989 Mon Sep 17 00:00:00 2001 From: DewanaGustavus <76590469+DewanaGustavus@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:55:38 +0700 Subject: [PATCH] fix: checkout --- src/App/components/cart/Cart.php | 4 ++-- src/App/controller/cart/CartController.php | 7 +++++++ .../{checkout => category}/CheckoutController.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) rename src/App/controller/{checkout => category}/CheckoutController.php (91%) diff --git a/src/App/components/cart/Cart.php b/src/App/components/cart/Cart.php index cf0b7cd..b143cc5 100644 --- a/src/App/components/cart/Cart.php +++ b/src/App/components/cart/Cart.php @@ -14,8 +14,8 @@ <div id="checkout-alert"></div> <?php - if($_SERVER["HTTP_REFERER"] == 'http://localhost:8000/Cart.php'){ - echo '<script>showCheckoutAlert("Checkout successful!");</script>';; + if($this->data['checkout']){ + echo '<script>showCheckoutAlert("Checkout successful!");</script>'; } include(dirname(__DIR__) . '/template/Navbar.php'); ?> diff --git a/src/App/controller/cart/CartController.php b/src/App/controller/cart/CartController.php index e773620..b46f235 100644 --- a/src/App/controller/cart/CartController.php +++ b/src/App/controller/cart/CartController.php @@ -6,6 +6,12 @@ class CartController extends Controller { throw new Exception("You are not allowed to view this page", 405); } + $isCheckout = false; + if($page === "checkout") { + $isCheckout = true; + $page = 1; + } + $cartModel = $this->model("CartModel"); $cart = $cartModel->getUserCart($_SESSION['user_id']); @@ -24,6 +30,7 @@ class CartController extends Controller { "data" => $cart, "page" => $page, "pageLimit" => $this->pageLimit, + "checkout" => $isCheckout, "cart" => $pageCart, "cartItems" => $cartItems, diff --git a/src/App/controller/checkout/CheckoutController.php b/src/App/controller/category/CheckoutController.php similarity index 91% rename from src/App/controller/checkout/CheckoutController.php rename to src/App/controller/category/CheckoutController.php index f99f9c5..9591226 100644 --- a/src/App/controller/checkout/CheckoutController.php +++ b/src/App/controller/category/CheckoutController.php @@ -15,7 +15,7 @@ class CheckoutController extends Controller{ } - header("Location: /Cart"); + header("Location: /cart/checkout"); } } -- GitLab