Forums / General Questions / 2 customers order same item (1 in stock) and checkout successfully

2 customers order same item (1 in stock) and checkout successfully

Locked

Started by colourfuldesigns on 25 Jul 2010, 11:10 PM · Views: 1,581

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
25 Jul 2010, 11:10 PM
#1
colourfuldesigns avatar

colourfuldesigns

New Zenner

Join Date:
Mar 2010
Posts:
13
Plugin Contributions:
0

2 customers order same item (1 in stock) and checkout successfully

The problem occurs when 2 people place an order for the same item when the stock level is low. When 2 orders are placed very close together they are both allowed to check out the same item.

If there is 1 left in stock and they both check out too close together both checkouts complete correctly, the result being you have sold the same single item twice.
All the stock control options set to not subtract stock and not allow checkout.

I haven't witnessed this myself, I have been told by a fellow zencart user that they have seen the same 'bug' on several occasions on their very busy site and have not found a solution here.
I have searched and not found anything in the forums.
He's using an unmodified install of zencart (version 1.3.8 I believe).

I've used zencart for a number of years on a quieter site, but this week I'm launching a new site which will sell out 1 product, 100 in stock in less than an hour, and I'm really concerned we will hit the same problem and sell more than we have stock for.

Can anyone tell me if this is an issue that has been raised before? Or been fixed? or anything?

Thanks

25 Jul 2010, 11:46 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: 2 customers order same item (1 in stock) and checkout successfully

That's just a fact of life, especially when you're commonly selling one-of-a-kind items.

Write the 2nd customer a very nice letter and invite them to select from some alternate similar products, or refund them entirely.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Jul 2010, 12:40 AM
#3
colourfuldesigns avatar

colourfuldesigns

New Zenner

Join Date:
Mar 2010
Posts:
13
Plugin Contributions:
0

Re: 2 customers order same item (1 in stock) and checkout successfully

Please tell me this isn't the only solution?

We will have 100 of a particular product, if we sell 101 of them, mr 101 will be really upset.
Its not that we are selling one of a kind products, its just that we have a limited stock.

Can it not be protected against by mutex or similar?

Surely someone else has seen this?
If not can I post it as a bug?

26 Jul 2010, 1:46 AM
#4
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,896
Plugin Contributions:
21

Re: 2 customers order same item (1 in stock) and checkout successfully

It's not a bug and there's no way of controlling this situation without tying cart sessions to stock.

Zen Cart allows you to put items in your cart without stopping someone else from doing so. Otherwise, I could go to your cart, put 100 of your widgets in my cart, and head out for the day never intending to buy anything.

Under your change, until my session died, no one would be able to order any widgets.

The way it works now, you could have 10 widgets left, and 15 people online with one in their cart. If all decide to complete through checkout, you'll be needing to contact some folks.

Personally, I see it as a good problem. At least a LOT better than someone tying up product for hours without buying.

I think we're talking the new DOP hack. (Denial of Product) :P

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

26 Jul 2010, 1:59 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: 2 customers order same item (1 in stock) and checkout successfully

ColourfulDesigns:

Please tell me this isn't the only solution?

We will have 100 of a particular product, if we sell 101 of them, mr 101 will be really upset.
Its not that we are selling one of a kind products, its just that we have a limited stock.

Can it not be protected against by mutex or similar?

Surely someone else has seen this?
If not can I post it as a bug?
I do understand your predicament, and you're not the first person to encounter such a situation. And I'm not trying to be contrary or antagonistic or belligerent just to be a pain. Please excuse the tone if it comes off that way. There are technical reasons for taking this position.

Please ... tell me just exactly how you propose the ideal solution to work?
I'm guessing you're going to say that as soon as someone puts the product in their cart you want to remove it from stock immediately, right? And then when the next person comes along they can't put it in their cart because it's no longer there since it's out of stock. But then the first person decides they like the price better somewhere else, or maybe they get distracted by a phone call and just abandon their cart. Meanwhile the second customer who was READY to buy and had their credit card in-hand, just waiting to give YOU money ... they can't get one, and YOU lose the sale. Aw shucks.
Making a refund is a LOT better than losing a sale. And, if the refund or offered-refund is done properly, it could actually convert into another sale and/or potentially several more sales or upsells. That customer will not be as "really upset" as you will be for having lost both sales since you made it impossible for the motivated buyer to actually buy something.

So, next you're going to tell me that some sort of automated process could then magically remove the items from abandoned carts and put them back in stock. Granted, that will happen LONG AFTER the 2nd customer has been refused opportunity to purchase what he had intended to buy and has since left your site and gone elsewhere to get it. So, that's not a total solution either.

Not to mention the fact that your competitors could easily roam around your store putting everything in a shopping cart and abandoning them, thus totally preventing all your customers from making purchases.

As dbltoe has stated, the software is working as-designed. It's not a bug.
Zen Cart already checks stock levels at every step of the checkout process right up until the last possible moment when payment is collected. If two customers happen to be clicking the "pay" button at the same instant, it is possible to get two completed legitimate sales.

Or is there some magical solution you're seeing that I'm not? I'm happy to listen to workable solutions.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Jul 2010, 8:18 AM
#6
jsweb avatar

jsweb

Zen Follower

Join Date:
Jul 2005
Location:
UK and Ireland
Posts:
392
Plugin Contributions:
0

Re: 2 customers order same item (1 in stock) and checkout successfully

That'squite a reply Dr Byte - too much coffee perhaps ;)

I once thought about this: if product A's stock level = 1 and someone has this product in their basket then on the product page it annouces that "a client has this product in their shopping basket; buy now before stock runs out"

It may help to quicken sales..

The JSWeb Team
Providing Zen Cart Hosting, Design and Support services to help your business succeed online!
JSWeb | UK / Ireland ZenCart Design and Hosting Specialists

26 Jul 2010, 8:41 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: 2 customers order same item (1 in stock) and checkout successfully

JSWeb:

That'squite a reply Dr Byte - too much coffee perhaps ;)Perhaps. Or maybe not enough.> JSWeb:

I once thought about this: if product A's stock level = 1 and someone has this product in their basket then on the product page it annouces that "a client has this product in their shopping basket; buy now before stock runs out"

It may help to quicken sales..Yes, it may help quicken sales, but doesn't actually solve the stated problem. Just exacerbates it.
And adds more database query hits in the process :blush: (potentially lots of queries depending on how many shoppers (active or not) have products in their cart.)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Jul 2010, 10:11 AM
#8
colourfuldesigns avatar

colourfuldesigns

New Zenner

Join Date:
Mar 2010
Posts:
13
Plugin Contributions:
0

Re: 2 customers order same item (1 in stock) and checkout successfully

DrBryte,

I fully understand the issue of holding carts, its pointless and achieves nothing helpful, I agree.
But there are other carts that don't see this issue, so either they are protecting against it or the timing is much tighter their reducing the possibility of it occurring.

I haven't done alot of sychronisation/mutexing etc in php, it is not my native language, I have however done it in other languages. I'm a hardware level software programmer for real time systems, were timing like this is absolutely cruecial.
So excuse me if the exact method is incorrect for php, but theory should still apply.

As I see it 2 possible solutions that come to mine:

  1. Using in built db synchronisation.
    When a person clicks the final part of checkout (not payment but the checkout of zencart) and we go to sql to do the check and subtract stock, we synchronise the access to that product, so only 1 thread (ie customer session) can check, subtract, check the stock level. When we have done that we can release the sync, the next thread trying to access the same product will then get access when it does its check it will see the stock level is already zero, release the sync, return to the customer and say out of stock.

  2. Creating a section of access checking for products.
    When a person clicks the final part of checkout (not payment but the checkout of zencart) can we check and subtract the stock
    (using sql to subtract the value, not reading it from the db minusing 1 and writing it back!),
    then recheck it, if its zero (and not a minus number) we can return to the customer and say checkout successful, if we get a minus number, we know we have had a hit and will have to put the stock for that customer back, and tell them it is now out of stock.
    Now due to timing it is entirely possible for both sessions to return the minus stock, so I believe we would have to associate a session id to the db access and use the one which chronologically comes first to allocate the stock.

There are millions of other ways php and sql are used where double subtraction of a value would be critical and there must be a way around that.

I understand that zencart is operating as designed, I just feel there is room for improvement in this area.

Thoughts?

26 Jul 2010, 10:39 AM
#9
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: 2 customers order same item (1 in stock) and checkout successfully

In your first post you are stating

ColourfulDesigns:

........All the stock control options set to ***not ***subtract stock and not allow checkout.....

If you don't subtract your sold items from stock on-hand then how pray tell can the system implement "don't allow checkout when there is no stock left" ??

Or was it a typo from your end ?

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

26 Jul 2010, 11:03 AM
#10
colourfuldesigns avatar

colourfuldesigns

New Zenner

Join Date:
Mar 2010
Posts:
13
Plugin Contributions:
0

Re: 2 customers order same item (1 in stock) and checkout successfully

Sorry that was a typo.
Its set to check stock, subtract stock, and now allow checkout.

26 Jul 2010, 6:04 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: 2 customers order same item (1 in stock) and checkout successfully

ColourfulDesigns:

I understand that zencart is operating as designed, I just feel there is room for improvement in this area.
I don't disagree. There's room for improvement. But it won't happen in the v1.3.x series. Maybe in v2 where the architecture is more flexible and more capable of some of the suggestions you offer.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Jul 2010, 11:58 PM
#12
colourfuldesigns avatar

colourfuldesigns

New Zenner

Join Date:
Mar 2010
Posts:
13
Plugin Contributions:
0

Re: 2 customers order same item (1 in stock) and checkout successfully

Ho hum, okay thanks.

If I write the code to do it in mean time I'll be sure to let you know.

31 Jul 2010, 7:02 PM
#13
colourfuldesigns avatar

colourfuldesigns

New Zenner

Join Date:
Mar 2010
Posts:
13
Plugin Contributions:
0

Re: 2 customers order same item (1 in stock) and checkout successfully

DrByte
I have now seen this issue in my own shop.
It is a bug, I have seen it manifest in a more concerning way.
When 2 people checkout with the same item in quick succession the stock is only subtracted once.
In the last 3hrs this has happened on 2 different producs, now the stock levels are higher than they should be. By 4 on one of our products. We will run out of real stock long before zencart believes we have. I will have to constantly re-check and manually adjust the stock levels to compensate.

This is a serious stock control bug, it is a fundametal of the way the stock control is working.
I'm going to go and investigate it now in order to achieve a fix.

31 Jul 2010, 9:09 PM
#14
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,896
Plugin Contributions:
21

Re: 2 customers order same item (1 in stock) and checkout successfully

When 2 people checkout with the same item in quick succession the stock is only subtracted once.
This leads me to believe there may be something else going on. The fact that the items are not being subtracted may not have anything to do with double orders.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com