SaaS CMS has officially launched! Learn more now.

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 12:31
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.
Vote:
 

I also get this intermittent inventory allocation issue in Commerce v13.24.  It's very intermittent and we could not replicate on other environments

The call to _inventoryProcessor.AdjustInventoryOrRemoveLineItem is in between payment and save cart into purchase order. There weren't any errors returned during the AdjustInventory call.

For a particular SKU, I can see the [dbo].[LineItems] table values for the two orders  as below (not even consecutive orders):

  • Order at 12:06 AM UTC
    • In Stock Quantity: 394
    • Quantity Purchased: 1
    • Is Inventory Allocated: true
  • Next order for the SKU at 4:27 AM UTC
    • In Stock Quantity: 394 (At this point, it should have been decreased to 393)
    • Quantity Purchased: 1
    • Is Inventory Allocated: true

After the last order done at 4:27AM, the stock has decreased to 393 (in reality, it should have been 392). 

Will there be any other possible cause(s) to this issue?

The stakeholders are a bit concerned that this issue may potentially happen for limited one-stock only items and that they don't want to oversell.

#262154
Sep 12, 2021 23:59
Johnny Mullaney - Sep 20, 2021 11:25
hey Shella :) we're experiencing an intermittent issue just like this causing overselling. keeping an eye on this ticket.
Vote:
 

There are a few examples here of sporadic issues with Inventory allocation causing overselling for customers at least up to Commerce v13.24.

Maybe somebody at Optimizely can let us know if this is recorded as a known issue?

#263472
Sep 21, 2021 15:23
Shella Cabatbat - Sep 21, 2021 22:27
I've raised a support ticket the other day since it's happening more frequent these days -- seems to happen a lot with the spike of sales -- since the shop currently has a campaign for this last quarter of the year. This honestly seems to be indicating cache or app-instance related.
Johnny Mullaney - Sep 22, 2021 8:57
Nice one Shella. Let me know if you find anything useful. Feels like the old days :)
Vote:
 

Curious if you run validate cart before processing any transaction? Validate cart should check following:

  • Validate your line items
  • Validate your placed price associated to the user accessing the cart
  • Validate inventory for all line items
  • Validate promotions

For all the above we have existing Optimizely API to trigger validation. In the case of inventory... it looks something like this 

cart.UpdateInventoryOrRemoveLineItems((item, issue) => AddValidationIssues(validationIssues, item, issue), _inventoryProcessor);

There is something else we always follow in our order processing:

Before processing the payment on a cart, we always reserve inventory so it is not used by someone else during the order creation process. We first mark the inventory InProgress. Following line tries to reserve inventory and will not allow to process if no inventory available.

this._inventoryProcessor.AdjustInventoryOrRemoveLineItem(cart.GetFirstShipment(), OrderStatus.InProgress, (item, issue) => { });

Do not forget to clear the reservation of inventory using Cancelled or Completed based on the events.

~ Sujit

#263634
Edited, Sep 23, 2021 17:29
Johnny Mullaney - Sep 24, 2021 15:10
Great suggestions Sujit
* 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.