购物车和库存管理

发布于 2024-08-03 14:57:00 字数 422 浏览 2 评论 0原文

我目前正在使用 PHP/MySQL 构建一个电子商务网站。最近,我一直在致力于购物车集成。客户希望确保潜在买家可以获得库存,因此我创建了一个库存管理系统。购物车的工作原理如下:

  • 客户将商品的数量添加到 他的购物车。
  • 商品数量保留自 数据库中的可用库存。
  • 其他人不能购买预留的 库存。
  • 库存保留至客户为止 处理订单 - 那么库存在哪里 从数据库中删除。
  • 如果客户放弃购物车,库存仍会保留。
  • 如果另一个客户希望购买商品,但另一个客户只保留了可用库存,那么如果该保留库存已闲置 20 分钟,则该客户可以窃取该保留库存。

我的问题是,这种情况的最佳实践是什么?我这样做正确吗?最主要的是客户不想出售他没有的股票。

我希望讨论如何改进功能,或者其他人正在做什么来实现这一目标。

I am currently building an ecommerce site with PHP/MySQL. Recently, I have been working on the Shopping Cart integration. The client wanted to ensure that stock was available to potential buyers, so I created a stock management system. The shopping cart works as follows:

  • Client adds a quantity of an item to
    his cart.
  • Item quantity is reserved from
    available stock in the database.
  • No one else can purchase reserved
    stock.
  • Stock remains reserved until client
    processes order - where stock is then
    removed from database.
  • If client abandons his cart, stock remains reserved.
  • If another client wishes to buy an item, but only available stock is reserved by another client, then the client can steal the reserved stock if it has been inactive for 20 minutes.

My question is, what are best practices for this kind of scenario? Am I doing this correctly? The main thing is that the client does not want to sell stock that he does not have.

I am looking to have a discussion on how to improve the functionality, or what others are doing to accomplish this.

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

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

发布评论

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

评论(2

本宫微胖 2024-08-10 14:57:00

另一种方法可能是在将库存放入购物车时不保留库存。每次重新加载页面时执行检查,如果该商品不再可用,则显示一条消息,例如“您要购买的商品刚刚售完。很快就会有货”。然后您从购物车中删除该产品。

现在,您绝对必须在启动付款操作之前保留购物车内容,然后根据付款的成功/失败将其从库存中删除或删除保留。您可以在一次代码运行中做得更好,以便保留时间尽可能短。

ProcessOrder ()
{
    bool reserved = ReserveShoppingCartContents ();
    if (reserved)
    {
        bool paymentStatus = ProcessPayment ();
        if (paymentStatus)
            RemoveShoppingCartContentsFromStock ();
        else
            ReleaseShoppingCartReserve ();
    }
    else
    {
        RefreshShoppingCartContents (); // Remove positions or adjust quantities
        MessageBox ("Could not reserve your shopping cart contents. Please check out your selection");
    }
}

您的保留时间越短,您的商品实际售出的机会就越大。您可以最大限度地减少冲突的可能性:客户 A 从购物车开始,商品被预订,客户 B 来,看到该商品没有库存并离开,客户 A 决定他不喜欢这个价格并取消操作。您有两个潜在客户,但无法向其中任何一个客户销售产品。

An alternative approach may be not to reserve a stock upon putting it in the shopping cart. Perform a check each time a page is reloaded, should the item be no more available, display a message like "The item you wish to buy has just been sold out. It will be available shortly". And you remove the product from the shopping cart.

Now, you absolutely have to reserve the shopping cart contents right before you initiate the payment operation, then either remove it from the stock or remove the reserve depending on the success/failure of the payment. You do it better in one code run, so that the reserve lasts as briefly as possible.

ProcessOrder ()
{
    bool reserved = ReserveShoppingCartContents ();
    if (reserved)
    {
        bool paymentStatus = ProcessPayment ();
        if (paymentStatus)
            RemoveShoppingCartContentsFromStock ();
        else
            ReleaseShoppingCartReserve ();
    }
    else
    {
        RefreshShoppingCartContents (); // Remove positions or adjust quantities
        MessageBox ("Could not reserve your shopping cart contents. Please check out your selection");
    }
}

The briefer your reserve lasts, the higher the chance your item will be actually sold. You minimize the possibility of a conflict: CustomerA begins with the shopping cart, the item gets reserved, CustomerB comes, sees the item is not on stock and goes away, CustomerA decides he doesn't like the price and cancels the operation. You had two potential customers but couldn't sell to either.

Smile简单爱 2024-08-10 14:57:00

在结账过程中,我会在每次重新加载页面时检查库存,如果在此过程中商品已售完,我会将其重定向到购物车页面并显示一条错误消息。
仅在订单确认后才会减少库存
如果订单被取消,我也会恢复库存。

i do a check for the stock on every reload of the pages during the checkout proccess and redirect them to the cart page with an error message if during the process the items have been sold out.
The stock is reduced only on order confirmed
Also i restore the stock if the order is canceled.

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