Skip to content

Instantly share code, notes, and snippets.

@Jonne
Created July 26, 2018 13:37
Show Gist options
  • Select an option

  • Save Jonne/e840a78b5cd2c3c237b353b21b2adc8c to your computer and use it in GitHub Desktop.

Select an option

Save Jonne/e840a78b5cd2c3c237b353b21b2adc8c to your computer and use it in GitHub Desktop.
var shippingParty = new CommerceParty
{
Name = Constants.ShippingAddressCommerceName
};
var parties = new List<Party> { shippingParty };
parties.AddRange(cart.Parties.ToList());
cart.Parties = parties;
// Always set external id to some magic number (Party in the loaded cart does not contain an ExternalId)
// the AddShippingInfoToCart processor looks for a ExternalId == PartyId
shippingParty.ExternalId = Guid.NewGuid().ToString("D");
var shippingInfo = new CommerceShippingInfo
{
ShippingMethodID = request.ShippingMethod.Id,
ExternalId = request.ShippingMethod.Id,
PartyID = request.Party?.ExternalId,
ShippingOptionType = request.ShippingMethod.ShippingOptionType,
ShippingMethodName = request.ShippingMethod.MethodName
};
var request = new global::Sitecore.Commerce.Engine.Connect.Services.Carts.AddShippingInfoRequest(cart,
new List<ShippingInfo> { shippingInfo }, request.ShippingMethod.ShippingOptionType);
var result = cartProvider.AddShippingInfo(request);
if (!result.Success)
{
var messages = result.SystemMessages.Select(m => m.Message);
throw new SystemException(string.Join(",", messages));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment