开发者

ASP.NET,C# :How to handle Shopping cart Problem

开发者 https://www.devze.com 2023-02-02 10:09 出处:网络
I am developing an e-commerce project, in this I have one crucial product that have only one ProductQuantity,and that product have quantity 1 so two person can not buy that product.

I am developing an e-commerce project, in this I have one crucial product that have only one ProductQuantity,and that product have quantity 1 so two person can not buy that product. at the time of AddToCart I have reduced the quantity from the database. I have test this with 10 machine and at th开发者_如何转开发e same time all 10 machine click on the AddToCart Button,but 3 machine is able to add the same product to own cart, which is wrong, only one machine(person) can add that product.

Please suggest me how to handle this scenario.

Thanks Vijendra


When you add to cart, you shouldn't really be removing one from the ProductQuantity, it should stay as is. Only when the order has been paid for do you drop it from the quantity.

Otherwise you end up with the scenario of someone coming to the site, adding a bunch of stuff to the cart, then leaving and never coming back, now all your products are 1 less in stock even tho your inventory would be 1 greater than ProductQuantity.

The products can display something like 'low in stock' or 'less than 5 available'. The end user knows there isn't many left, then when you get to the checkout, you can confirm the quantity to ensure it hasn't been sold prior while the user was fluffing around. If the product is now out of stock, then display a message saying it's no longer in stock.

The flipside of the coin here is, it's going to be rare for you to have a scenario where this actually occurs, unless your site is really popular.


Edit: Additional answer to address 'I want 10 people' comment

If you say you want 10 people to try add it, with only 1 person to successfully add it, then you are doing yourself out of business.

If User A add's the product to the cart, User B cannot.

User B leaves the site looking for where he can buy the product.

User A then leaves cos he decided he no longer wants the product, the product is now back in the database, and you have lost a potential sale.


After the first time that "Add To Cart" is clicked, have you checked the database to verify that the count has indeed reduced to 0?

Secondly, once the count is at 0, have you verified that additional clicks to "Add to Cart" check the quantity field to make sure that there is sufficient quantity to fill their order?

I suspect that the problem is with one or the other of these two areas...

0

精彩评论

暂无评论...
验证码 换一张
取 消