Support the ongoing development of Laravel.io →
Configuration Database Packages
Last updated 1 year ago.
0

The best way to achieve this is to simply sell the item to the first person that purchases it, and then have different "states" and order can be in. States can include "ordered" "shipped" "complete" "back ordered" "refunded"

Step 1 of the checkout procedure is to check if there is an item left, The final step of the checkout is reduce the quantity by 1.

If there is 1 item left and both users enter the checkout form and submit seconds apart the system will process the first request, the second request will check the quantity which will now be 0 because the first checkout took it.

All you need is a special check in code that checks to see if the user completes a transaction and if the quantity is zero, then you set the state of the order "back ordered" You can display a special message to the user and give them the option to cancel.

In e-commerce you never want to not take someone's money. If it later turns out that you can't order more of that product you do a refund or exchange for a similar products.

Having states on the orders is a great way of tracking orders in the backend. Shippers need to look at orders that are "ready to ship" then they can change it to "shipped", users can track the "state" of their orders... etc.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

vivekdave vivekdave Joined 19 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.