Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 333251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:56:38+00:00 2026-05-12T09:56:38+00:00

I am currently building an ecommerce site with PHP/MySQL. Recently, I have been working

  • 0

I am currently building an ecommerce site with PHP/MySQL. Recently, I have been working on the Shopping Cart integration. The client wanted to ensure that stock was available to potential buyers, so I created a stock management system. The shopping cart works as follows:

  • Client adds a quantity of an item to
    his cart.
  • Item quantity is reserved from
    available stock in the database.
  • No one else can purchase reserved
    stock.
  • Stock remains reserved until client
    processes order – where stock is then
    removed from database.
  • If client abandons his cart, stock remains reserved.
  • If another client wishes to buy an item, but only available stock is reserved by another client, then the client can steal the reserved stock if it has been inactive for 20 minutes.

My question is, what are best practices for this kind of scenario? Am I doing this correctly? The main thing is that the client does not want to sell stock that he does not have.

I am looking to have a discussion on how to improve the functionality, or what others are doing to accomplish this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:56:38+00:00Added an answer on May 12, 2026 at 9:56 am

    An alternative approach may be not to reserve a stock upon putting it in the shopping cart. Perform a check each time a page is reloaded, should the item be no more available, display a message like “The item you wish to buy has just been sold out. It will be available shortly”. And you remove the product from the shopping cart.

    Now, you absolutely have to reserve the shopping cart contents right before you initiate the payment operation, then either remove it from the stock or remove the reserve depending on the success/failure of the payment. You do it better in one code run, so that the reserve lasts as briefly as possible.

    ProcessOrder ()
    {
        bool reserved = ReserveShoppingCartContents ();
        if (reserved)
        {
            bool paymentStatus = ProcessPayment ();
            if (paymentStatus)
                RemoveShoppingCartContentsFromStock ();
            else
                ReleaseShoppingCartReserve ();
        }
        else
        {
            RefreshShoppingCartContents (); // Remove positions or adjust quantities
            MessageBox ("Could not reserve your shopping cart contents. Please check out your selection");
        }
    }
    

    The briefer your reserve lasts, the higher the chance your item will be actually sold. You minimize the possibility of a conflict: CustomerA begins with the shopping cart, the item gets reserved, CustomerB comes, sees the item is not on stock and goes away, CustomerA decides he doesn’t like the price and cancels the operation. You had two potential customers but couldn’t sell to either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building in Version 3.5 of the .Net framework and I have
I am currently building a web site and I just implemented SqlCacheDependency using LinqToSQL
I'm building an ecommerce site using S#arp Architecture. I'm trying to map a hierachy
I'm currently building a site where I want anonymous users to see a page
I am currently building an ASP MVC 2 site and I am looking at
I'm currently building a web-based file upload/download hub for a company that wanted an
I'm currently building a Java app that could end up being run on many
I am currently building an internal web application used in a factory/warehouse type location.
We're currently building an application that executes a number of external tools. We often
I'm currently building a small web application that includes a fair amount of JavaScript.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.