Inventory Adjustment Interference

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 года назад
We experience a  situation , when admin was canceling an order at the same time a customer place an order and Stock quantity history changed as follow:

1 - product attribute combination was 12
2 - a customer bought 1 and stock quantity history became 11
3 - admin cancel an order with quantity of 1 and stock quantity became 13

I thought we  should  put a LOCK for AdjustInventory method but it may cause slow order placement when several orders are placing at the same time.

What's the solution and what does the big online stores like Amazon and eBay do?
3 года назад
Sombody !!??
3 года назад
something like this:


private object mutex = new object();

/// <summary>
/// Adjust inventory
/// </summary>
/// <param name="product">Product</param>
/// <param name="quantityToChange">Quantity to increase or decrease</param>
/// <param name="attributesXml">Attributes in XML format</param>
/// <param name="message">Message for the stock quantity history</param>
/// <returns>A task that represents the asynchronous operation</returns>
public virtual async Task AdjustInventoryAsync(Product product, int quantityToChange, string attributesXml = "", string message = "")
{
  lock (mutex)
    {
    //inventory adjust codes
    ......
  }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.