ASP.NET,C#:如何处理购物车问题

发布于 2024-10-10 00:12:57 字数 228 浏览 1 评论 0原文

我正在开发一个电子商务项目,在这个项目中,我有一个关键产品,它只有一个产品数量,并且该产品的数量为 1,所以两个人不能购买该产品。 在 AddToCart 时,我减少了数据库中的数量。 我用 10 台机器对此进行了测试,同时所有 10 台机器都单击“添加到购物车”按钮,但 3 台机器能够将相同的产品添加到自己的购物车,这是错误的,只有一台机器(人)可以添加该产品。

请建议我如何处理这种情况。

谢谢 维詹德拉

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 the 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铁轨上的流浪者 2024-10-17 00:12:57

当您添加到购物车时,您实际上不应该从 ProductQuantity 中删除一件产品,它应该保持原样。只有当订单已付款后,您才可以从数量中删除它。

否则,您最终会遇到这样的情况:有人来到该网站,向购物车添加了一堆东西,然后离开,再也没有回来,现在您所有产品的库存都减少了 1,即使您的库存比 ProductQuantity 大 1。

产品可能会显示“库存不足”或“可用数量少于 5 个”之类的信息。最终用户知道剩下的数量不多了,那么当您到达结账处时,您可以确认数量,以确保在用户闲逛时它没有被售出。如果该产品现在缺货,则显示一条消息,说明该产品不再有库存。

硬币的另一面是,除非您的网站非常受欢迎,否则很少会出现这种情况。


编辑:针对“我想要 10 个人”评论的附加答案

如果您说您希望 10 个人尝试添加它,但只有 1 个人成功添加它,那么您正在让自己破产。

如果用户 A 将产品添加到购物车,用户 B 则不能。

用户 B 离开网站寻找可以购买该产品的地方。

然后用户 A 离开,因为他决定不再需要该产品,该产品现在又回到数据库中,并且您失去了潜在的销售机会。

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.

杯别 2024-10-17 00:12:57

第一次点击“添加到购物车”后,您是否检查过数据库以验证计数确实已减少到 0?

其次,一旦计数为 0,您是否验证了“添加到购物车”的额外点击次数是否检查了数量字段,以确保有足够的数量来填写订单?

我怀疑问题出在这两个区域中的一个或另一个......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文