From 04b48f006771e882a14ee75ea49e74d5bf33f97b Mon Sep 17 00:00:00 2001 From: xxl4 Date: Wed, 26 Feb 2025 07:04:55 +0000 Subject: [PATCH] fix the coupon code --- .../Controllers/Customer/CartController.php | 14 +++++++++++++- .../Api/V1/Shop/Customer/CartController.php | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Docs/V1/Shop/Controllers/Customer/CartController.php b/src/Docs/V1/Shop/Controllers/Customer/CartController.php index df4b83d..97f4cbd 100644 --- a/src/Docs/V1/Shop/Controllers/Customer/CartController.php +++ b/src/Docs/V1/Shop/Controllers/Customer/CartController.php @@ -522,7 +522,12 @@ public function moveToWishlist() * property="code", * type="string", * example="FLAT10" - * ) + * ), + * @OA\Property( + * property="cart_id", + * type="integer", + * example=1 + * ), * ) * ) * ), @@ -559,6 +564,13 @@ public function applyCoupon() * summary="Remove cart coupon", * description="Remove cart coupon", * security={ {"sanctum": {} }}, + * + * @OA\RequestBody( + * @OA\Property( + * property="cart_id", + * type="integer", + * example=1 + * ), * * @OA\Response( * response=200, diff --git a/src/Http/Controllers/Api/V1/Shop/Customer/CartController.php b/src/Http/Controllers/Api/V1/Shop/Customer/CartController.php index 63731c4..3832e98 100644 --- a/src/Http/Controllers/Api/V1/Shop/Customer/CartController.php +++ b/src/Http/Controllers/Api/V1/Shop/Customer/CartController.php @@ -178,11 +178,6 @@ public function store($productId): JsonResponse ], 400); } } - public function add($product_id) - { - print_r(123);exit; - } - /** * Updates the quantity of the items present in the cart. @@ -263,6 +258,11 @@ public function empty() public function applyCoupon(Request $request) { $couponCode = $request->code; + $cart_id = $request->input("cart_id"); + if($cart_id) { + $cart = $this->cartRepository->find($cart_id); + Cart::setCart($cart); + } try { if (strlen($couponCode)) { @@ -296,8 +296,14 @@ public function applyCoupon(Request $request) * * @return \Illuminate\Http\Response */ - public function removeCoupon() + public function removeCoupon(Request $request) { + $cart_id = $request->input("cart_id"); + if($cart_id) { + $cart = $this->cartRepository->find($cart_id); + Cart::setCart($cart); + } + Cart::removeCouponCode()->collectTotals(); $cart = Cart::getCart();