Before Bagisto v2.5.1, a Buy Now click could empty the shopper’s cart. Bagisto now runs each of these purchases on a separate cart.
A shopper has two products in the cart. On a third product page, they click Buy Now to order that one product right away.
Before Bagisto v2.5.1, that click emptied the shopper’s cart. The two products they had saved were gone.
Bagisto now handles that purchase on a separate cart. The shopper’s cart keeps every product in it.
The first half of this post explains the change for store owners. The second half shows developers how it works in the code.
Up to Bagisto v2.5.0, that click replaced the shopper’s cart with a new one. The new cart held only the product the shopper clicked.
Bagisto never brought the old cart back, so its products were lost.
The shopper lost the cart in every case. It made no difference whether they paid, canceled the payment, or closed the tab.
Two checkouts in two tabs also shared one cart. The second click changed the product in the first tab’s checkout.
The Bagisto v2.5.1 release on November 6, 2026 fixed this behavior.
Many shoppers use the cart as a list of products to buy later, not only as a step before checkout.
Baymard Institute found that 42% of US online shoppers have left a cart because they were just browsing.
Baymard also lists saving items for later as a normal way to use a cart.
An emptied cart sends these shoppers back to search for every product again.
Since Bagisto v2.5.1, the shopper’s cart stays the main cart. Each Buy Now click creates a separate cart.
The separate cart holds only the product the shopper is buying. Checkout runs on the separate cart alone.
Bagisto also adds a backup copy of the product to the shopper’s cart. If the shopper does not finish, the product stays there.
When the order completes, Bagisto removes the backup copy. The shopper’s cart then looks the way it did before the click.
| What the shopper does | Before Bagisto v2.5.1 | Since Bagisto v2.5.1 |
|---|---|---|
| Completes the purchase | Loses the cart | Keeps the cart as it was |
| Cancels the payment | Loses the cart | Keeps the cart, plus the product |
| Closes the checkout tab | Loses the cart | Keeps the cart, plus the product |
| Opens two checkouts in two tabs | The second tab replaces the first | Each tab gets its own separate cart |
The v2.5.1 upgrade guide lists every method this design added to the Cart class.
The shopper below had two products in the cart before clicking Buy Now on a watch.
The checkout’s Cart Summary lists only the watch, because checkout runs on the separate cart.
If the shopper leaves checkout, the cart page still holds both earlier products and the backup copy of the watch.
Pressing Back after paying does not reopen the checkout. Bagisto shows the order’s success page instead.
A guest who signs in during the purchase keeps it. Bagisto moves the guest’s separate cart to the customer account.
Bagisto ships with Buy Now disabled. Go to Configure > Catalog > Products and find Product view page configuration.
Enable Allow customers to directly buy products, then click Save Configuration.
The Buy Now button then appears beside Add To Cart on every product page.
The rest of this post is for developers.
After the click, Bagisto sends the shopper to checkout with a buy_now token in the URL.
The token is the separate cart’s ID, encrypted with Laravel’s encryption service.
A changed token fails to decrypt, and the URL never shows the sequential cart ID.
The ResolveBuyNowCart middleware reads the token on every storefront request:
|
1 2 3 4 5 |
if ($token = $request->input('buy_now')) { if ($cartId = Cart::parseBuyNowToken($token)) { Cart::useBuyNowCart($cartId); } } |
The useBuyNowCart() method first checks that the visitor owns the cart.
A guest owns the separate carts their session created. A customer owns the ones that carry their customer ID.
The switch lasts for one request only. The session still points to the shopper’s cart.
The checkout page adds the token to every request it sends. The address, shipping, and payment steps all work on the separate cart.
A redirect gateway sends the shopper to the payment site and back. Both trips need to find the same separate cart.
Bagisto registers the middleware as cart.buy_now, and every payment gateway’s route group now uses it:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Route::controller(StripeController::class) ->middleware(['web', 'cart.buy_now']) ->prefix('stripe') ->group(function () { Route::get('redirect', 'redirect') ->name('stripe.standard.redirect'); Route::get('success', 'success') ->name('stripe.payment.success'); Route::get('cancel', 'cancel') ->name('stripe.payment.cancel'); }); |
A middleware alias lets a gateway add this with one entry in its route group.
Bagisto also adds the token to the gateway’s redirect URL. The shopper then returns to the same separate cart.
Stripe, PayPal, PayU, PayGlocal, and PhonePe used to refuse an inactive cart. They now make an exception for the separate cart.
After every order, an event listener on checkout.order.save.after runs this method:
|
1 2 3 |
public function onOrderPlaced($order): void { Cart::removeBuyNowItemsFromBasket($order->cart_id); } |
For an order from a separate cart, the method takes the bought quantity out of the shopper’s cart. It ignores orders from a regular cart.
Submitting the same purchase twice does not create a second order. Bagisto returns the order the separate cart already has.
One case still leaves the backup copy behind. A guest who pays on a redirect gateway and never returns keeps the product in the cart.
In that case, only the gateway’s webhook places the order. The webhook has no guest session to find the cart with.
A custom payment gateway may need up to three changes to support Buy Now.
First, add the cart.buy_now alias to the gateway’s route group, the same way the Stripe routes above do.
Second, if the gateway refuses inactive carts before it places an order, let the separate cart through:
|
1 2 3 4 5 6 7 8 9 |
if ( ! $cart || ( ! $cart->is_active && ! $cart->is_buy_now ) ) { return null; } |
Third, if the gateway’s return URL has no reference to the cart, add the token to it. Razorpay and PayPal Standard do this.
The payment method guide covers the rest of a gateway package.
|
1 |
php artisan migrate |
With a separate cart for every Buy Now, shoppers buy one product right away and keep the rest of their cart.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.