Magento version: 2.3.5-p1
(magento/module-inventory-sales) version: 1.0.8
The backorder quantity shown in checkout and stored in
qty_backordered can be wrong when there are reservations for the product. The backorder quantity is calculated using the current stock count, not the salable count which considers reservations.
- Global config: Decrease Stock When Order is Placed = Yes.
- Product config: stock qty = 2, no reservations, manage stock = Yes, out of stock threshold = 0, backorders = Allow Qty Below 0 and Notify.
- Add to cart 1 qty (no backorder shown). Place order.
- Add to cart 2 qty (no backorder shown, but should be 1 qty).
- Add to cart 1 qty (3 total). (1 qty backorder shown, but should be 2 qty).
- Place order. (1 qty backorder stored in
qty_backordered, but should be 2 qty).
The culprit is here:
$backOrderQty = $requestedQty - $stockItemData[GetStockItemDataInterface::QUANTITY];
The stock qty is being used to calculate the backorder qty, so reservations are not considered.
It's not even consistent in ignoring reservations though, as they are correctly considered when checking if add to cart should be allowed here:
I know that this is due to the order not being shipped yet, so the stock isn't being decreased yet. But still, surely this isn't intentional? You cannot sell the same salable qty multiple times to different customers. I haven't found an answer for this, which makes me think I'm missing something. Thanks in advance.