Created
July 26, 2018 13:37
-
-
Save Jonne/e840a78b5cd2c3c237b353b21b2adc8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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