Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    redirect issue after storeOrder

    General Discussion
    2
    2
    778
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kenninh last edited by

      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'),
      ]);

      A 1 Reply Last reply Reply Quote 0
      • A
        ashif.322 @kenninh last edited by

        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.

        1. 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.

        2. 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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post