Don't miss out Virtual Happy Hour today (April 26).

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 

Introduction

This document provides some basic examples of how to use the ECF API to work with multi-shipment, also known as "split shipments". The multi-shipment feature allows purchased items to be shipped to multiple address. For example, when a customer buys two items A and B, it is possible to have the items shipped to two different addresses. The addresses to be used can be created during checkout, or selected from existing addresses.

How it works

This section describes how multi-shipment is implemented in the Commerce sample templates. When a customer has purchased at least two items, the "Multi-shipment checkout" option will be presented during checkout.

Page Types

During checkout, the information for each "split shipping" part is added. The number of "split shipments" is equivalent to the number of items in the cart, and it is possible to add individual shipment addresses for each item.

Page Types

Upon completing the information for each split shipment part, the page will be reloaded to update the summary for each shipment, as well as the total summary.

New addresses that can be used for both billing and shipping, can be created in each split shipment part.

Page Types

Code examples

Example: Getting the billing address

C#
var Cart = new CartHelper(Mediachase.Commerce.Orders.Cart.DefaultName);
var billingAddressId = Cart.OrderForms[0].BillingAddressId;
var billingAddress = Cart.OrderAddresses.ToArray().FirstOrDefault(x =>
x.Name.Equals(billingAddressId));

Example: Creating split shipment parts based on line items

C#
var lineItems = Cart.OrderForms[0].LineItems;
foreach (LineItem lineItem in lineItems)
{
        Shipment shipment = new Shipment();
        shipment.CreatorId = SecurityContext.Current.CurrentUserId.ToString();
        shipment.Created = DateTime.UtcNow;
shipment.AddLineItemIndex(lineItems.IndexOf(lineItem), lineItem.Quantity);
        Cart.OrderForms[0].Shipments.Add(shipment);
}
Cart.AcceptChanges();

Example: Adding a shipping address to a cart

C#
 Shipment shipment = Cart.OrderForms[0].Shipments.ToArray().FirstOrDefault();
if (shipment == null)
{
    shipment = new Shipment();
     shipment.CreatorId = SecurityContext.Current.CurrentUserId.ToString();
    shipment.Created = DateTime.UtcNow;
}

shipment.ShippingAddressId = address.Name;

if (Cart.OrderForms[0].Shipments.Count < 1)
{
    Cart.OrderForms[0].Shipments.Add(shipment);
}

Example: Adding a shipment method to a cart

C#
/Shipment ship = Cart.OrderForms[0].Shipments.ToArray().Where(s => s.Id ==      this.SplitShipment.Id).FirstOrDefault();
ship.ShippingMethodId = new Guid(shippingMethodId);
ship.ShippingMethodName = ((GlobalRadioButton)sender).Text;

//Calculate shipping, disocunts, totals, etc    
OrderGroupWorkflowManager.RunWorkflow(Cart,                                                     
OrderGroupWorkflowManager.CartPrepareWorkflowName);
Cart.AcceptChanges();
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 21, 2014

Recommended reading