/// <summary> /// Sets the shipping methods. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="inputModel">The input model.</param> /// <returns> /// The manager response where the modified CommerceCart is returned in the Result. /// </returns> public virtual ManagerResponse <AddShippingInfoResult, CommerceCart> SetShippingMethods([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] SetShippingMethodsInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); var result = new AddShippingInfoResult { Success = false }; var response = this.GetCurrentCart(storefront, visitorContext, true); if (!response.ServiceProviderResult.Success || response.Result == null) { return(new ManagerResponse <AddShippingInfoResult, CommerceCart>(result, response.Result)); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (inputModel.ShippingAddresses != null && inputModel.ShippingAddresses.Any()) { var cartParties = cart.Parties.ToList(); cartParties.AddRange(inputModel.ShippingAddresses.ToParties()); cart.Parties = cartParties.AsReadOnly(); } var internalShippingList = inputModel.ShippingMethods.ToShippingInfoList(); var orderPreferenceType = InputModelExtension.GetShippingOptionType(inputModel.OrderShippingPreferenceType); if (orderPreferenceType != ShippingOptionType.DeliverItemsIndividually) { foreach (var shipping in internalShippingList) { shipping.LineIDs = (from CommerceCartLine lineItem in cart.Lines select lineItem.ExternalCartLineId).ToList().AsReadOnly(); } } var cartCache = CommerceTypeLoader.CreateInstance <CartCacheHelper>(); cartCache.InvalidateCartCache(visitorContext.GetCustomerId()); result = this.AddShippingInfoToCart(cart, orderPreferenceType, internalShippingList); if (result.Success && result.Cart != null) { cartCache.AddCartToCache(result.Cart as CommerceCart); } return(new ManagerResponse <AddShippingInfoResult, CommerceCart>(result, result.Cart as CommerceCart)); }
public ManagerResponse <AddShippingInfoResult, CommerceCart> SetShippingMethods(string userId, SetShippingMethodsInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); var result = new AddShippingInfoResult { Success = false }; var response = GetCart(userId, true); if (!response.ServiceProviderResult.Success || response.Result == null) { return(new ManagerResponse <AddShippingInfoResult, CommerceCart>(result, response.Result)); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (inputModel.ShippingAddresses != null && inputModel.ShippingAddresses.Any()) { var cartParties = cart.Parties.ToList(); cartParties.AddRange(inputModel.ShippingAddresses.Select(item => item.ToParty()).ToList()); cart.Parties = cartParties.AsReadOnly(); } var internalShippingList = inputModel.ShippingMethods.Select(item => item.ToShippingInfo()).ToList(); var orderPreferenceType = InputModelExtension.GetShippingOptionType(inputModel.OrderShippingPreferenceType); if (orderPreferenceType != ShippingOptionType.DeliverItemsIndividually) { foreach (var shipping in internalShippingList) { shipping.LineIDs = (from CommerceCartLine lineItem in cart.Lines select lineItem.ExternalCartLineId).ToList().AsReadOnly(); } } CartCacheHelper.InvalidateCartCache(userId); result = AddShippingInfoToCart(cart, orderPreferenceType, internalShippingList); if (result.Success && result.Cart != null) { CartCacheHelper.AddCartToCache(result.Cart as CommerceCart); } return(new ManagerResponse <AddShippingInfoResult, CommerceCart>(result, result.Cart as CommerceCart)); }
public virtual ManagerResponse<AddShippingInfoResult, CommerceCart> SetShippingMethods([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] SetShippingMethodsInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); var result = new AddShippingInfoResult { Success = false }; var response = this.GetCurrentCart(storefront, visitorContext, true); if (!response.ServiceProviderResult.Success || response.Result == null) { return new ManagerResponse<AddShippingInfoResult, CommerceCart>(result, response.Result); } CommerceParty allShippingParty = null; var emailPartyList = this.GetEmailAddressPartiesFromShippingMethods(inputModel.ShippingMethods); var cart = (CommerceCart)response.ServiceProviderResult.Cart; if ((inputModel.ShippingAddresses != null && inputModel.ShippingAddresses.Any()) || (emailPartyList != null && emailPartyList.Any())) { var addPartiesResult = this.SetShippingAddresses(storefront, visitorContext, cart, inputModel.ShippingAddresses, emailPartyList); if (!addPartiesResult.Success) { result.SystemMessages.Add(addPartiesResult.SystemMessages[0]); return new ManagerResponse<AddShippingInfoResult, CommerceCart>(result, result.Cart as CommerceCart); } cart = (CommerceCart)addPartiesResult.Cart; allShippingParty = (CommerceParty)addPartiesResult.Parties.ElementAt(0); } var internalShippingList = inputModel.ShippingMethods.ToShippingInfoList(); var orderPreferenceType = InputModelExtension.GetShippingOptionType(inputModel.OrderShippingPreferenceType); if (orderPreferenceType != RefSFModels.ShippingOptionType.DeliverItemsIndividually) { foreach (var shipping in internalShippingList) { shipping.LineIDs = (from CommerceCartLine lineItem in cart.Lines select lineItem.ExternalCartLineId).ToList().AsReadOnly(); shipping.PartyID = allShippingParty.ExternalId; } } var cartCache = CommerceTypeLoader.CreateInstance<CartCacheHelper>(); cartCache.InvalidateCartCache(visitorContext.GetCustomerId()); result = this.AddShippingInfoToCart(cart, orderPreferenceType, internalShippingList); if (result.Success && result.Cart != null) { cartCache.AddCartToCache(result.Cart as CommerceCart); } return new ManagerResponse<AddShippingInfoResult, CommerceCart>(result, result.Cart as CommerceCart); }
/// <summary> /// Sets the shipping methods. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="inputModel">The input model.</param> /// <returns> /// The manager response where the modified CommerceCart is returned in the Result. /// </returns> public virtual ManagerResponse<AddShippingInfoResult, CommerceCart> SetShippingMethods([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] SetShippingMethodsInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); var result = new AddShippingInfoResult { Success = false }; var response = this.GetCurrentCart(storefront, visitorContext, true); if (!response.ServiceProviderResult.Success || response.Result == null) { return new ManagerResponse<AddShippingInfoResult, CommerceCart>(result, response.Result); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (inputModel.ShippingAddresses != null && inputModel.ShippingAddresses.Any()) { var cartParties = cart.Parties.ToList(); cartParties.AddRange(inputModel.ShippingAddresses.ToParties()); cart.Parties = cartParties.AsReadOnly(); } var internalShippingList = inputModel.ShippingMethods.ToShippingInfoList(); var orderPreferenceType = InputModelExtension.GetShippingOptionType(inputModel.OrderShippingPreferenceType); if (orderPreferenceType != Sitecore.Commerce.Connect.DynamicsRetail.Entities.Shipping.ShippingOptionType.DeliverItemsIndividually) { foreach (var shipping in internalShippingList) { shipping.LineIDs = (from CommerceCartLine lineItem in cart.Lines select lineItem.ExternalCartLineId).ToList().AsReadOnly(); } } var cartCache = CommerceTypeLoader.CreateInstance<CartCacheHelper>(); cartCache.InvalidateCartCache(visitorContext.GetCustomerId()); result = this.AddShippingInfoToCart(cart, orderPreferenceType, internalShippingList); if (result.Success && result.Cart != null) { cartCache.AddCartToCache(result.Cart as CommerceCart); } return new ManagerResponse<AddShippingInfoResult, CommerceCart>(result, result.Cart as CommerceCart); }