Skip to content

Configure Warehouses

⏱ 20 minutes intermediate
📜Corecommerce

Multi-warehouse fulfillment reduces shipping costs and delivery times by placing inventory closer to customers. Commerce tracks stock independently per warehouse and uses allocation rules to decide which warehouse fulfills each order. Proper configuration ensures that orders route to the right warehouse, stock stays balanced, and customers receive accurate delivery estimates.

This guide covers creating warehouses, setting up allocation rules, and distributing inventory across locations.

  1. Create warehouse records in Commerce
  2. Associate warehouses with markets
  3. Configure allocation rules for order routing
  4. Distribute inventory across warehouses

Each warehouse represents a physical location that can fulfill orders. Define its address, operating hours, and capabilities.

In the Commerce UI:

  1. Navigate to Commerce > Administration > Warehouses
  2. Click Add Warehouse
  3. Enter the warehouse name, code, and address
  4. Set the warehouse as active
  5. Enable fulfillment and pickup options as needed
Create a warehouse programmatically
csharp
using Mediachase.Commerce.Catalog;
using Mediachase.Commerce.Catalog.Dto;

public class WarehouseService
{
    private readonly IWarehouseRepository
        _warehouseRepo;

    public WarehouseService(
        IWarehouseRepository warehouseRepo)
    {
        _warehouseRepo = warehouseRepo;
    }

    public IWarehouse CreateWarehouse(
        string name, string code,
        string city, string state,
        string countryCode)
    {
        var warehouse = new Warehouse
        {
            Name = name,
            Code = code,
            IsActive = true,
            IsFulfillmentCenter = true,
            IsPickupLocation = false,
            ContactInformation = new WarehouseContact
            {
                City = city,
                State = state,
                CountryCode = countryCode
            }
        };

        _warehouseRepo.Save(warehouse);
        return warehouse;
    }
}

Each market can use a subset of your warehouses. This controls which warehouses are eligible to fulfill orders for customers in that market.

Link warehouses to markets
csharp
using Mediachase.Commerce;
using Mediachase.Commerce.Markets;

public void AssociateWarehouseWithMarket(
    IMarketService marketService,
    string marketId,
    string warehouseCode)
{
    var market = marketService
        .GetMarket(new MarketId(marketId))
        as MarketImpl;

    if (market != null)
    {
        var fulfillmentWarehouses =
            market.WarehouseCodesForFulfillment
                .ToList();

        if (!fulfillmentWarehouses
            .Contains(warehouseCode))
        {
            fulfillmentWarehouses.Add(warehouseCode);
            market.WarehouseCodesForFulfillment =
                fulfillmentWarehouses;
            marketService.UpdateMarket(market);
        }
    }
}

Allocation rules determine which warehouse fulfills a given order. Common strategies include geographic proximity, inventory availability, and priority-based routing.

Warehouse allocation logic
csharp
public class WarehouseAllocator
{
    private readonly IWarehouseRepository _warehouseRepo;
    private readonly IInventoryService _inventoryService;

    public WarehouseAllocator(
        IWarehouseRepository warehouseRepo,
        IInventoryService inventoryService)
    {
        _warehouseRepo = warehouseRepo;
        _inventoryService = inventoryService;
    }

    public string SelectWarehouse(
        IEnumerable<string> eligibleCodes,
        IEnumerable<ILineItem> items)
    {
        foreach (var code in eligibleCodes)
        {
            var canFulfill = items.All(item =>
            {
                var records = _inventoryService
                    .QueryByEntry(
                        new[] { item.Code });
                var record = records.FirstOrDefault(
                    r => r.WarehouseCode == code);
                return record != null
                    && record.PurchaseAvailableQuantity
                        >= item.Quantity;
            });

            if (canFulfill) return code;
        }

        return null; // No single warehouse can fulfill
    }
}

Allocation strategies:

StrategyBest forTrade-off
Nearest warehouseMinimizing shipping timeRequires geocoding and distance calculation
Highest stockPreventing stockouts at busy locationsMay increase shipping distance
Priority listSimple setups with a primary and backup warehouseDoes not optimize for cost or speed
Split fulfillmentLarge orders with distributed inventoryIncreases packaging and shipping costs

When you add new stock, distribute it across warehouses based on demand patterns and geographic coverage.

Distribution approachDescription
Even splitDivide stock equally across all active warehouses
Demand weightedAllocate more stock to warehouses with higher sales volume
RegionalStock products only in warehouses that serve the relevant market
IssueCauseFix
Orders not routing to the nearest warehouseAllocation rules using priority list instead of proximityImplement geographic-based allocation with address distance calculation
Warehouse shows zero stock after importInventory records imported with wrong warehouse codeVerify warehouse codes match between import file and Commerce configuration
Market shows no fulfillment optionsWarehouse not associated with the marketLink the warehouse to the market in Commerce admin
Split shipments creating extra shipping chargesAllocation allowing multi-warehouse fulfillmentAdd a single-warehouse preference before falling back to split fulfillment