Try our conversational search powered by Generative AI!

Loading...
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Note: This feature has been obsoleted in the latest version of the product.

Introduction

This document provides some basic examples of how to use the ECF API to work with multi-warehouse features. Examples covered here are for instance how to get listings of warehouses and getting inventories per warehouse.

Multi-warehouse features

Examples of listing of warehouses and inventories.

Page Types

Example: Getting a list of warehouses

C#
// Get list Warehouse
public IEnumerable<IWarehouse> ListAllWarehouses()
{
    var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>();
    return warehouseRepository.List();
}

Example: Getting warehouse by ID or warehouse code

C#
// Get list Warehouse by ID
public IWarehouse GetWarehouse(int warehouseId)
{
    var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>();

    return warehouseRepository.Get(warehouseId);
}
C#
// Get list Warehouse by Code
public IWarehouse GetWarehouse(string warehouseCode)
{
    var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>();

    return warehouseRepository.Get(warehouseCode);
}

Note: It is preferable to use the warehouse code, which will most likely be more meaningful in a business context.

For more details on this example, refer to WarehouseHelper.cs in the EPiServer.Commerce.Sample project.

Page Types

Example: Picking up an item from a warehouse and add to a cart

C#
//Add an entry from a warehouse to Cart
CartHelper cartHelper = new CartHelper(Cart.DefaultName);
cartHelper.AddEntry(entry, quantity, false, warehouseCode);

Example: Listing warehouse codes for an entry

C#
//List warehouse of an entry
Entry entryInventory =  CatalogContext.Current.GetCatalogEntry(entry.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Inventory));
var listWarehouseByEntry = entryInventory.WarehouseInventories.WarehouseInventory;
    var warehouseCodes = listWarehouseByEntry.Select(w => w.WarehouseCode);

In store pick-up

Examples of how to create a shipping with pick-up in store, and make it display in the checkout process.

Page Types

Example: Getting the "In store pick-up" method name

C#
// Get Pickup shipping method name
string pickupMethodName = ShippingManager.PickupShippingMethodName;

Example: Checking if the shipping method is a pick-up method or not

C#
// Check shipping method is pick-up shipment
string pickupMethodName;
ShippingManager.IsHandoffShippingMethod(pickupMethodName);

Example: Picking up an entry and adding it to a cart

C#
var cartHelper = new CartHelper(Mediachase.Commerce.Orders.Cart.DefaultName);
var cart = cartHelper.Cart;
var lineItems = cart.OrderForms[0].LineItems.ToArray().FirstOrDefault();

Shipment shipment = new Shipment();
shipment.CreatorId = SecurityContext.Current.CurrentUserId.ToString();
shipment.Created = DateTime.UtcNow;
shipment.AddLineItemIndex(lineItems.IndexOf(lineItem), lineItem.Quantity);
// Note that lineItem.WarehouseCode should have been determined ahead of time, for example, 
// by calling a workflow containing GetFulfillmentWarehouseActivity, such as the CartPrepare workflow.
shipment.WarehouseCode = lineItem.WarehouseCode;

// Check warehouse is Pickup location, shipping method will be "In store pickup".
IWarehouse warehouse = WarehouseHelper.GetWarehouse(lineItem.WarehouseCode);
if (warehouse.IsPickupLocation)
{
    // Add address to OrderAddress and Shipment.
    if (cartHelper.FindAddressByName(warehouse.Name) == null)
    {
        var address = warehouse.ContactInformation.ToOrderAddress();
        address.Name = warehouse.Name;
        cart.OrderAddresses.Add(address);
    }

    shipment.ShippingAddressId = warehouse.Name;
    shipment.ShippingMethodName = ShippingManager.PickupShippingMethodName;

    var instorepickupShippingMethod = ShippingManager.GetShippingMethods("en").ShippingMethod.ToArray().Where(m => m.Name.Equals(ShippingManager.PickupShippingMethodName)).FirstOrDefault();
    if (instorepickupShippingMethod != null)
    {
        shipment.ShippingMethodId = instorepickupShippingMethod.ShippingMethodId;
    }
}

cart.OrderForms[0].Shipments.Add(shipment);
cart.AcceptChanges();

Doing this, the checkout process will move the entry to In store pickup shipments.

Page Types

For more details on this example, refer to MultiShipmentCheckout.ascx.cs in the EPiServer.Commerce.Sample project.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 31, 2014

Recommended reading