redirect issue after storeOrder
-
After checkout and Place Order, the order created successfully and the cart is cleared but the Place Order page remains. Should it redirect to the success page?
In function storeOrder, is this correct?
Cart::deActivateCart();
session()->flash('order_id', $order->id);
return new JsonResource([
'redirect' => true,
'redirect_url' => route('shop.checkout.onepage.success'),
]); -
Hello @kenninh
You're right on both points — here's what's happening.
The success page relies on the order id being stored in the session like this:
session()->flash('order_id', $order->id);Flash data in Laravel only lives for ONE request. That single detail explains both behaviors you're seeing.
-
Refreshing the success page redirects to the cart
This is normal/expected. The success page reads order_id once and renders it.
On refresh the flashed value is already gone, so there's no order to show and
it falls back to the cart page. Nothing needs fixing here. -
Sometimes it goes straight to the cart instead of the success page
This is the real issue. Because the value survives only one request, if any
other request touches the session between "Place Order" and the success page
loading, the order_id gets consumed early and is lost. Common triggers:- a background request (mini-cart / cart summary) firing during the redirect
- a double click or browser prefetch
- a slow or non-shared session store (e.g. multiple servers behind a load
balancer without a shared session driver)
That timing race is why it only happens sometimes.
Thanks
Team Bagisto -