购物车和库存管理 [英] Shopping cart and stock management

查看:221
本文介绍了购物车和库存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用PHP/MySQL构建一个电子商务网站.最近,我一直在从事Shopping Cart集成.客户希望确保库存可供潜在买家使用,因此我创建了一个库存管理系统.购物车的工作方式如下:

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:

  • 客户将一定数量的项目添加到 他的购物车.
  • 项目数量从保留 数据库中的可用库存.
  • 没有其他人可以购买保留的 库存.
  • 库存一直保留到客户 处理订单-当时的库存 已从数据库中删除.
  • 如果客户放弃购物车,库存将保留.
  • 如果另一位客户希望购买商品,但另一位客户只保留了可用的库存,那么如果闲置了20分钟的客户没有库存,则该客户可以窃取该库存.
  • 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.

推荐答案

另一种方法可能是不将股票放入购物车中就保留股票.每次重新加载页面时,请执行检查,如果该物品不再可用,则显示一条消息,例如您想要购买的物品已经售罄.不久将可用".然后,您从购物车中删除了产品.

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");
    }
}

您的储备期越短,您的商品被实际出售的机会就越高.您将发生冲突的可能性降到最低:CustomerA从购物车开始,该商品被保留,CustomerB来回,看到该商品没有库存而消失,CustomerA决定他不喜欢这个价格并取消了该操作.您有两个潜在客户,但无法卖给任何一个.

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.

这篇关于购物车和库存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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