/// <summary> /// To the shipping information. /// </summary> /// <param name="item">The item.</param> /// <returns>A CommerceShippingInfo.</returns> public static ShippingInfo ToShippingInfo(this ShippingMethodInputModelItem item) { var shippingInfo = new ShippingInfo { PartyID = item.PartyID, ShippingMethodID = item.ShippingMethodID, LineIDs = item.LineIDs != null?item.LineIDs.AsReadOnly() : new List <string>().AsReadOnly() }; return(shippingInfo); }
public static CommerceShippingInfo ToShippingInfo(this ShippingMethodInputModelItem item) { var shippingInfo = new CommerceShippingInfo { PartyID = item.PartyId, ShippingMethodID = item.ShippingMethodID, ShippingMethodName = item.ShippingMethodName, ShippingOptionType = GetShippingOptionType(item.ShippingPreferenceType), ElectronicDeliveryEmail = item.ElectronicDeliveryEmail, ElectronicDeliveryEmailContent = item.ElectronicDeliveryEmailContent, LineIDs = item.LineIDs?.AsReadOnly() ?? new List <string>().AsReadOnly() }; return(shippingInfo); }
private void SetShippingMethods(CheckoutViewModel model) { var inputModel = new SetShippingMethodsInputModel(); var shipItemsLines = model.Cart.Lines.Where(l => model.LineShippingOptions[l.ExternalCartLineId].Name == "Ship items"); PartyInputModelItem address = GetPartyInputModelItem(); if (address != null) { inputModel.ShippingAddresses.Add(address); } else { return; } inputModel.OrderShippingPreferenceType = "1"; var shipItemsMethod = new ShippingMethodInputModelItem(); string shippingOptionID = GetShippingOptionID(model); shipItemsMethod.ShippingMethodID = shippingOptionID; shipItemsMethod.ShippingMethodName = model.ShippingOptions[shippingOptionID]; shipItemsMethod.ShippingPreferenceType = "1"; shipItemsMethod.PartyId = "0"; shipItemsMethod.LineIDs = shipItemsLines.Select(l => l.ExternalCartLineId).ToList(); inputModel.ShippingMethods.Add(shipItemsMethod); try { var response = CartManager.SetShippingMethods(CommerceUserContext.Current.UserId, inputModel); if (!response.ServiceProviderResult.Success || response.Result == null) { throw new Exception("Error setting shipping methods: " + string.Join(",", response.ServiceProviderResult.SystemMessages.Select(sm => sm.Message))); } model.Cart = response.Result; } catch (Exception e) { throw; } }
private void SetShippingMethods(CheckoutViewModel model) { var inputModel = new SetShippingMethodsInputModel(); var digitalLines = model.Cart.Lines.Where(l => model.LineShippingOptions[l.ExternalCartLineId].Name == "Digital"); var shipItemsLines = model.Cart.Lines.Where(l => model.LineShippingOptions[l.ExternalCartLineId].Name == "Ship items"); PartyInputModelItem address = GetPartyInputModelItem(); string email = Request.Cookies["email"]?.Value; if (digitalLines.Any() && shipItemsLines.Any() && address != null && !string.IsNullOrWhiteSpace(email)) { inputModel.OrderShippingPreferenceType = "4"; } else if (digitalLines.Any() && !shipItemsLines.Any() && !string.IsNullOrWhiteSpace(email)) { inputModel.OrderShippingPreferenceType = "3"; } else if (!digitalLines.Any() && shipItemsLines.Any() && address != null) { inputModel.OrderShippingPreferenceType = "1"; } else { return; } if (new[] { "4", "1" }.Contains(inputModel.OrderShippingPreferenceType)) { if (address != null) { inputModel.ShippingAddresses.Add(address); } var shipItemsMethod = new ShippingMethodInputModelItem(); string shippingOptionID = GetShippingOptionID(model); shipItemsMethod.ShippingMethodID = CleanGuid(shippingOptionID); shipItemsMethod.ShippingMethodName = model.ShippingOptions[shippingOptionID]; shipItemsMethod.ShippingPreferenceType = "1"; shipItemsMethod.PartyId = "0"; shipItemsMethod.LineIDs = shipItemsLines.Select(l => l.ExternalCartLineId).ToList(); inputModel.ShippingMethods.Add(shipItemsMethod); } if (new[] { "4", "3" }.Contains(inputModel.OrderShippingPreferenceType)) { var emailMethod = new ShippingMethodInputModelItem(); Item emailItem = Context.Database.GetItem("/sitecore/Commerce/Commerce Control Panel/Shared Settings/Fulfillment Options/Digital/Email"); emailMethod.ShippingMethodID = CleanGuid(emailItem.ID.ToString()); emailMethod.ShippingMethodName = "Email"; emailMethod.ShippingPreferenceType = "3"; emailMethod.ElectronicDeliveryEmail = email; emailMethod.ElectronicDeliveryEmailContent = ""; emailMethod.LineIDs = digitalLines.Select(l => l.ExternalCartLineId).ToList(); inputModel.ShippingMethods.Add(emailMethod); } try { var response = CartManager.SetShippingMethods(CommerceUserContext.Current.UserId, inputModel); if (!response.ServiceProviderResult.Success || response.Result == null) { throw new Exception("Error setting shipping methods: " + string.Join(",", response.ServiceProviderResult.SystemMessages.Select(sm => sm.Message))); } model.Cart = response.Result; } catch (Exception e) { throw; } }