HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Multi-shipment examples

Describes how to work with multi-shipment in Optimizely Customized Commerce, also known as split shipment, which supports shipment to multiple address.

A split shipment could be a customer who buys two items, and each is shipped to a different address. During checkout, a customer can create a new address, or select from existing addresses.

If a customer purchases two or more items, the Ship to multiple addresses button appears during checkout.

1221

During checkout, the information for each split shipping part is added. The number of split shipments is equal to the number of items in the cart, so the customer can add/select a shipping address for each item.

1139

Upon completing the information for each split shipment, the order process moves to next step. Here, choosing a shipping delivery option, billing address, and payment is required.

1003

Example: Creating multiple shipment for Cart base on cart's LineItem

var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
    var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
    var cart = orderRepository.LoadCart(CustomerContext.Current.CurrentContactId, DefaultCartName, currentMarket);
    var form = cart.GetFirstForm();
    var cartLineItems = cart.GetAllLineItems().ToList();
    
    // Clean up line item in shipment
    foreach (var shipment in form.Shipments)
      {
        shipment.LineItems.Clear();
      }
    // Clean up shipments
    form.Shipments.Clear();
    
    // Adding shipment for each cart line item
    foreach (var item in cartLineItems)
      {
        var shipment = cart.CreateShipment(_orderGroupFactory);
        var lineItem = cart.CreateLineItem(item.Code, _orderGroupFactory);
        lineItem.IsGift = item.IsGift;
        lineItem.Quantity = item.Quantity;
        shipment.LineItems.Add(lineItem);
        form.Shipments.Add(shipment);
      }
    
    orderRepository.Save(cart);