Inventory level not accurate

Vote:
 

We having an issue relating to inventory levels and behaviour that results in the overselling items that should have 0 inventory and be out of stock.
The issue is intermittent and happening a number of times every day.
We are also unable to replicate the issue locally in development nor in internal test environment so appears to be isolated to the DXC live environment.

Has anyone else experienced a similar issues ?

Having added some logging to try understand what is happening, we can see what appears to be happening is inventory is returning to it’s previous level a short period of time after hitting zero, an example from our logs:

Order placed for last item in stock:

  • Purchased at: 09:41
  • Item SKU: XXXXXX11
  • Expected stock level: 1
  • Log shows inventory query returns stock level 1 before placing the order:
    • 09:41:45, [Pre-Purchase] Stock levels for item XXXXXX11: 1
  • Log shows inventory query returns stock level 0 after placing the order:
    • 09:41:48, [Post-Purchase] Stock levels for item XXXXXX11: 0

Next order placed on the same say when item is out of stock:

  • Purchased at: 11:45
  • Item: XXXXXX11
  • Expected stock level: 0
  • Log shows inventory query returns stock level 1 before placing the order
    • 11:45:13, [Pre-Purchase] Stock levels for item XXXXXX11: 1
  • Log shows inventory query returns stock level 0 after placing the order
    • 11:45:23, [Post-Purchase] Stock levels for item XXXXXX11: 0

Note these log entries are from the same application server so we do not believe this is a load balancing issue

The following code snippets detail the processing of orders within the solution:

 

....Following successful payment

// Save cart as purchase order with an initial status of 'On Hold'

var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);

 

// Load saved purchase order asset status

var purchaseOrder = _orderRepository.Load<IPurchaseOrder>(orderReference.OrderGroupId);

purchaseOrder.OrderStatus = OrderStatus.InProgress;

purchaseOrder.PricesIncludeTax = true;

 

// Ensure shipment has warehouse code and inventory status

var shipment = purchaseOrder.GetFirstShipment();

shipment.WarehouseCode = _warehouseSettingsProvider.DefaultWarehouseCode;

shipment.OrderShipmentStatus = OrderShipmentStatus.InventoryAssigned;

 

// Save purchase order changes and remove the cart

_orderRepository.Save(purchaseOrder);

_orderRepository.Delete(cart.OrderLink);

 

// Run inventory activity

_inventoryProcessor.AdjustInventoryOrRemoveLineItem(shipment, purchaseOrder.OrderStatus, (item, issue) => validationIssues.Add(item, issue));

_orderRepository.Save(purchaseOrder);

... Continue with displaying order confirmation

4 times per day an order status import occurs which updates the order status to completed and shipping status to shipped:

var purchaseOrder = _purchaseOrderRepository.Load(trackingNumber);

if (purchaseOrder != null)

{

    order.Id = purchaseOrder.OrderLink.OrderGroupId;

    var shipment = purchaseOrder.GetFirstShipment();

    shipment.ShipmentTrackingNumber = courierTrackingNumber;

    shipment.OrderShipmentStatus = OrderShipmentStatus.Shipped;

    purchaseOrder.OrderStatus = OrderStatus.Completed;

 

    _orderRepository.Save(purchaseOrder);

    _mailService.SendDispatchEmail(emailAddress, order);

}

Has anyone experienced any similar issues ?

Is there anything in the code snippets you can see that should be executed differently, or any steps missing ?

The project is using CMS v11.11.2, Commerce v12.17.2

Thanks,

Stephen

#207765
Edited, Oct 02, 2019 17:27
Vote:
 

We are experiencing similar issue with Inventory. Its not returning accurate number and that results in overselling products. 

our investigation is in very early stage. This issue happens when there is sudden jump in customer's traffic and i believe this happen when concurrent users tries to checkout. I was thinking to disable cache for catalog but i believe Eiserver do not cache inventory. 

#208715
Oct 30, 2019 18:48
Stephen Myers - Dec 16, 2019 18:34
Thanks for your reply Naveed,
We have also explored the possibility this is related to spike in traffic big enough to trigger azure scaling the app service, however we have come to no conclusions as yet and are continuing to attempt to get to the bottom of this issue.
Vote:
 

Hi Stephen

It is probably not the root cause of your issue, but you could call _inventoryProcessor.AdjustInventoryOrRemoveLineItem on the cart, before saving it as a purchase order. If it returns any validation issues you can continue with the adjusted cart, or you can abort the process and show an error message.

And when your job runs to change the order status, do you also commit the inventory reservations (by calling _inventoryProcessor.AdjustInventoryOrRemoveLineItem again)? I would put it between setting the new order status and saving the purchase order object.

#208726
Oct 31, 2019 7:56
Stephen Myers - Dec 17, 2019 10:35
Thanks Stefan, I'll dig into inventory status further to determine if this is being committed correctly.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.