LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2010, 11:21 AM   #1
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Rep: Reputation: 56
mysql - online store inventory control


Hi all, I am adding inventory control to our online store here at work and I'm not sure of the best approach.

Let's say Customer A and Customer B are both looking at the product page for Product X at the same time, and there is only 1 left in stock. What should happen if both click "add to cart" at (more or less) the same time?

Should the last Product X get put "on hold" for one of the customers, and then decremented once the sale is complete? Or should the database decrement the product count, and then increment it if the sale doesn't go through successfully?

Is it still possible for both to add it to their cart? Are there any mysql features I can use to ensure both cannot purchase the last product?

Thanks!

[Edit: Also, what if a customer adds a product to their cart, and then leaves it there for a week?]

Last edited by mattca; 10-26-2010 at 11:29 AM.
 
Old 10-26-2010, 04:38 PM   #2
Mark1986
Member
 
Registered: Aug 2008
Location: Netherlands
Distribution: Xubuntu
Posts: 87

Rep: Reputation: 11
Hi mattca,

Both should be able to put the article in their cart.

Here is what happens most likely:

They both add to cart.
One will be the first to actually order.
At the moment he orders, you query the database and remove 1 of that article. This leaves the number to 0.
The second customer tries to order, your script should check the number. It finds 0 and thus cannot order that article.

The way you handle the database yourself is important. Make sure you check the quantity of an article just before someone starts to pay. No check will mean the amount of the article will just go to -1.

Best way to check if all will go well is to write or draw your process. You'll see the flaws (if any) straight away.
 
1 members found this post helpful.
Old 10-27-2010, 11:47 AM   #3
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Original Poster
Rep: Reputation: 56
Thanks, Mark, that is really helpful.

I'm only seeing one problem. If we decrement the inventory count when the user starts the checkout process, we need to increment it again if the sale is not completed. Currently we're using a third party shopping cart, and it doesn't notify us if a sale is not completed.

Actually, that wouldn't help anyway because we would have no way of being notified if the customer, for example, simply walked away from their computer without completing the sale.

I think the best we can do is put a timer on it, and then increase the inventory again once the timer expires.

In that case, maybe it makes sense to put the item "on hold", rather than removing it from the store. Kind of like putting a product in a physical shopping cart at an actual store. It hasn't been removed from the store's inventory yet, and if you leave the store without checking out, it'll eventually find its way back to the shelf.

Thanks again!

[Edit: actually, after thinking about it more I don't think the "on hold" solution is feasible. It would involve a counter for each and every individual product.. that would be a lot to manage. There must be a better way.]

Last edited by mattca; 10-27-2010 at 12:08 PM.
 
Old 10-28-2010, 01:08 AM   #4
Mark1986
Member
 
Registered: Aug 2008
Location: Netherlands
Distribution: Xubuntu
Posts: 87

Rep: Reputation: 11
For popular items, you can also just use what a lot of computer hardware stores use. Tell your customers with a green, yellow or red flag if the product is in supply. Use different delivery times for each flag. And let the paying process actually discount every article. That means you will get negative numbers in your system on your stocks. You then know you sold articles you need to get more of.

Example, article A:

Green flag: 100 pieces in stock.
Yellow flag: 40 pieces in stock.
Red flag: 10 pieces in stock.

Green flag: delivery within 5 working-days.
Yellow flag: delivery within 10 working-days.
Red flag: delivery within 20 working-days.

This means you don't need a real-time up-to-date stock. And you allow yourself 4 weeks of getting new stock in case it is needed.

Please note: I just came up with some random easy to calculate numbers. I have no experience with stocks what-so-ever. You'll have to think of your best settings yourself.

Hope this has helped you.
 
Old 10-28-2010, 11:08 AM   #5
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Original Poster
Rep: Reputation: 56
Thanks again Mark, that is helpful. But, unfortunately doesn't work in my case. We're implementing inventory control because we recently started selling "limited edition" products - products that we only have a certain amount of, and will never again be able to sell.

Your solution would make a lot of sense if we could continue selling the products - we could easily see how many we need to fulfill existing orders. But in my case, we absolutely have to prevent a customer from ordering a product once is it sold out.
 
Old 10-29-2010, 01:57 AM   #6
Mark1986
Member
 
Registered: Aug 2008
Location: Netherlands
Distribution: Xubuntu
Posts: 87

Rep: Reputation: 11
In that case, why not take something of the following?

You mention the fact that it's limited edition products.
Let your user order the product, not yet pay.
The order is sent to your system.
State that you have received their order and will send a confirmation back.
You now got all the orders and are able to see who gets the products and send them the e-mail. E-mail those who are not able to get the product about that fact and offer something else.
When you send them the e-mail, you require they pay within 8 or 30 days or something.

This way you never give out products you don't have.

Just slow the confirmation by a minute, this won't lose you any customers.
In case 2 customers order at about the same time for the last product, your system will give out 1 product and send an e-mail to the other stating the product is out of stock. (Of course with extra advertising for surrogate products or whatever.)
You keep both customers, one really happy, the other less happy but thinks it's nice to have some alternatives.

Just my next thoughts on the subject. Correct me if I'm wrong. Also note that I have not done this myself before.
 
Old 10-29-2010, 06:53 PM   #7
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Don't decrement stock when the user adds it to the cart - otherwise someone could just add everything to a cart with no intentions of paying but would mean no-one else could order! You should let both add the part and then do a check at the point of order confirmation.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Source Inventory Management Control System? firedude Linux - Software 4 10-08-2011 02:40 PM
best/cheapest online store for DVD-R spindles? hedpe General 1 12-31-2005 04:29 AM
LXer: Designing an Effective Online Store LXer Syndicated Linux News 0 12-29-2005 03:01 AM
store inventory system snoopy Linux - Enterprise 1 05-18-2004 07:56 PM
libnss-mysql (Store your UNIX user accounts in MySQL) markus1982 Linux - Security 0 01-26-2003 02:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration