如何管理为多个用户同时添加购物车相同的产品? [英] how to do manage add cart same product for multiple user at same time ?

查看:122
本文介绍了如何管理为多个用户同时添加购物车相同的产品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发添加到购物车模块。我有一个产品只有一个产品数量,而且该产品的数量为1所以两个人不能买那个产品。在AddToCart时我减少了数据库的数量。



我有一个问题:



如何同时为多个用户管理同一产品?

请建议我如何做到这一点。

hello all ,

I am working on add to cart module .I have one product that have only one Product Quantity, 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 a question:

how to do manage same product for multiple user at same time ?
please suggest me how to do this .

推荐答案

你需要在查询中使用 TRANSACTION ,在数据库中插入订单详细信息。



添加到购物车时,如果时间相同,则无法确定是否有其他用户添加了它。在下订单时,您的查询将只允许一个交易,并且在完成之后它将处理另一个请求。



因此,当两个请求都将到达数据库时,一个人会先经历。然后,当第二个进入时,您应该在查询中检查以查看是否有剩余的产品数量。如果有任何剩余,则允许插入,否则不显示并向用户显示此时产品不可用的消息。
You need to use TRANSACTION in the query which inserts the order details in the database.

While adding to the cart, you cannot determine whether any other user has added it or not, if the time is same. While placing the order, your query will allow only one transaction and after the completion of that it will process another request.

So, when both request will hit the database, one will go through first. Then when second goes, you should have a check inside the query to see if there is any quantity left for the product or not. If there is any left, then allow insert, otherwise not and show message to user that the product is not available at this moment.


这篇关于如何管理为多个用户同时添加购物车相同的产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆