From 40c8d613bae396265f146510b1de3fbb64eb657f Mon Sep 17 00:00:00 2001 From: DualFroz Date: Fri, 2 Oct 2026 16:42:10 +0200 Subject: [PATCH] fix(checkout): don't skip the edit page of a one-plan product in the cart --- app/Livewire/Products/Checkout.php | 2 +- tests/Feature/CheckoutTest.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Products/Checkout.php b/app/Livewire/Products/Checkout.php index bac7185..64e54a9 100644 --- a/app/Livewire/Products/Checkout.php +++ b/app/Livewire/Products/Checkout.php @@ -92,7 +92,7 @@ class Checkout extends Component // As there is only one plan, config options and checkout config, we can directly call the checkout method to avoid confusion // This is only done when the user is not editing the cart item - if ($this->product->plans->count() === 1 && empty($this->configOptions) && empty($this->checkoutConfig)) { + if ($this->product->plans->count() === 1 && empty($this->configOptions) && empty($this->checkoutConfig) && !$this->cartProductKey) { $this->checkout(); } } diff --git a/tests/Feature/CheckoutTest.php b/tests/Feature/CheckoutTest.php index aa79abb..30e5d2d 100644 --- a/tests/Feature/CheckoutTest.php +++ b/tests/Feature/CheckoutTest.php @@ -72,6 +72,28 @@ class CheckoutTest extends TestCase ]); } + public function test_checkout_page_does_not_redirect_if_one_plan_when_editing_cart_item(): void + { + $this->get(route('products.checkout', [ + $this->product->product->category->slug, + $this->product->product->slug, + ]))->assertRedirect(route('cart')); + + $cart = Cart::where('currency_code', 'USD')->firstOrFail(); + $item = $cart->items()->firstOrFail(); + + Once::flush(); + + $response = $this->withCookie('cart', $cart->ulid)->get(route('products.checkout', [ + $this->product->product->category->slug, + $this->product->product->slug, + 'edit' => $item->id, + ])); + + $response->assertStatus(200); + $response->assertSee($this->product->product->name); + } + public function test_checkout_page_with_multiple_plans(): void { // Add plan