Skip to content

Manage Inventory

⏱ 20 minutes intermediate
πŸ“œCorecommerce

Inventory accuracy determines whether customers can buy what they see. Overselling creates fulfillment failures and refund requests. Underselling leaves revenue on the table. Commerce tracks stock at the warehouse level, giving you precise control over what is available, what is on backorder, and when to reorder.

This guide covers setting inventory records, configuring reorder points, and handling backorder scenarios.

  1. Set inventory records for variants
  2. Configure reorder points to trigger restocking
  3. Enable backorder handling for out-of-stock items
  4. Query inventory across warehouses

Each inventory record ties a variant to a warehouse with a specific quantity. You must set IsTracked to true for Commerce to decrement stock on purchase.

Create and update inventory records
csharp
using Mediachase.Commerce.InventoryService;

public class InventoryManager
{
    private readonly IInventoryService _inventoryService;

    public InventoryManager(IInventoryService inventoryService)
    {
        _inventoryService = inventoryService;
    }

    public void SetStock(string variantCode,
        string warehouseCode, decimal quantity)
    {
        var record = new InventoryRecord
        {
            CatalogEntryCode = variantCode,
            WarehouseCode = warehouseCode,
            PurchaseAvailableQuantity = quantity,
            PurchaseAvailableUtc = DateTime.UtcNow,
            IsTracked = true
        };

        _inventoryService.Save(new[] { record });
    }

    public decimal GetAvailableStock(
        string variantCode, string warehouseCode)
    {
        var records = _inventoryService.QueryByEntry(
            new[] { variantCode });

        return records
            .Where(r => r.WarehouseCode == warehouseCode)
            .Sum(r => r.PurchaseAvailableQuantity);
    }
}

Reorder points define the stock threshold at which you should replenish inventory. Commerce does not automatically place purchase orders, but you can monitor levels and trigger notifications.

Monitor reorder thresholds
csharp
public class ReorderMonitor
{
    private readonly IInventoryService _inventoryService;
    private const decimal DefaultReorderPoint = 10m;

    public ReorderMonitor(IInventoryService inventoryService)
    {
        _inventoryService = inventoryService;
    }

    public IEnumerable<ReorderAlert> CheckReorderLevels(
        string warehouseCode)
    {
        var allRecords = _inventoryService
            .QueryByWarehouse(warehouseCode);

        return allRecords
            .Where(r => r.PurchaseAvailableQuantity
                <= DefaultReorderPoint)
            .Select(r => new ReorderAlert
            {
                VariantCode = r.CatalogEntryCode,
                CurrentStock = r.PurchaseAvailableQuantity,
                ReorderPoint = DefaultReorderPoint,
                Warehouse = warehouseCode
            });
    }
}

public class ReorderAlert
{
    public string VariantCode { get; set; }
    public decimal CurrentStock { get; set; }
    public decimal ReorderPoint { get; set; }
    public string Warehouse { get; set; }
}

Backorders let customers purchase items that are temporarily out of stock. Set the backorder quantity and the expected availability date so customers know when to expect shipment.

Configure backorder settings
csharp
public void EnableBackorder(string variantCode,
    string warehouseCode, decimal backorderQty,
    DateTime expectedDate)
{
    var record = new InventoryRecord
    {
        CatalogEntryCode = variantCode,
        WarehouseCode = warehouseCode,
        PurchaseAvailableQuantity = 0,
        PurchaseAvailableUtc = DateTime.UtcNow,
        BackorderAvailableQuantity = backorderQty,
        BackorderAvailableUtc = expectedDate,
        IsTracked = true
    };

    _inventoryService.Save(new[] { record });
}
SettingPurpose
PurchaseAvailableQuantityUnits in stock and ready to ship now
BackorderAvailableQuantityUnits customers can order before the restock date
BackorderAvailableUtcDate when backordered items become available
IsTrackedSet to true to decrement on purchase; false for unlimited (digital goods)
IssueCauseFix
Stock not decrementing after purchaseIsTracked set to falseSet IsTracked = true on the inventory record
Backorder option not showingBackorderAvailableQuantity is zeroSet a positive backorder quantity and future date
Wrong stock shown on storefrontQuerying incorrect warehouseVerify market-to-warehouse mapping in Commerce configuration
Overselling despite trackingRace condition under high concurrencyUse IInventoryService transactional methods for atomic updates