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.
Example: Getting a list of warehouses
C#
public IEnumerable<IWarehouse> ListAllWarehouses()
{
var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>();
return warehouseRepository.List();
}
Example: Getting warehouse by ID or warehouse code
C#
public IWarehouse GetWarehouse(int warehouseId)
{
var warehouseRepository = ServiceLocator.Current.GetInstance<IWarehouseRepository>();
return warehouseRepository.Get(warehouseId);
}
C#
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.
Example: Picking up an item from a warehouse and add to a cart
C#
CartHelper cartHelper = new CartHelper(Cart.DefaultName);
cartHelper.AddEntry(entry, quantity, false, warehouseCode);
Example: Listing warehouse codes for an entry
C#
var warehouseCodes = ServiceLocator.Current.GetInstance<IInventoryService>().QueryByEntry(new [] {"code"}.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.
Example: Getting the "In store pick-up" method name
C#
string pickupMethodName = ShippingManager.PickupShippingMethodName;
Example: Checking if the shipping method is a pick-up method or not
C#
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);
shipment.WarehouseCode = lineItem.WarehouseCode;
IWarehouse warehouse = WarehouseHelper.GetWarehouse(lineItem.WarehouseCode);
if (warehouse.IsPickupLocation)
{
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.
For more details on this example, refer to MultiShipmentCheckout.ascx.cs in the EPiServer.Commerce.Sample project (install a sample site).
Do you find this information helpful? Please log in to provide feedback.