/// <summary> /// Sets the shipping addresses. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="cart">The cart.</param> /// <param name="shippingAddresses">The shipping addresses.</param> /// <param name="emailPartyList">The email party list.</param> /// <returns> /// The manager response with a cart in the result. /// </returns> protected virtual AddPartiesResult SetShippingAddresses(CommerceStorefront storefront, VisitorContext visitorContext, CommerceCart cart, List<PartyInputModelItem> shippingAddresses, List<RefSFModels.EmailParty> emailPartyList) { var errorResult = new AddPartiesResult { Success = false }; var removePartiesResponse = this.RemoveAllShippingParties(storefront, visitorContext, cart); if (!removePartiesResponse.ServiceProviderResult.Success) { errorResult.SystemMessages.Add(removePartiesResponse.ServiceProviderResult.SystemMessages[0]); return errorResult; } List<Party> partyList = new List<Party>(); if (shippingAddresses != null && shippingAddresses.Any()) { partyList.AddRange(shippingAddresses.ToNewShippingParties()); } if (emailPartyList != null && emailPartyList.Any()) { partyList.AddRange(emailPartyList.Cast<Party>().ToList()); } AddPartiesRequest addPartiesRequest = new AddPartiesRequest(cart, partyList); var addPartiesResponse = this.CartServiceProvider.AddParties(addPartiesRequest); return addPartiesResponse; }
/// <summary> /// Populates the stock information of the given wish list. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="wishList">The wish list.</param> protected virtual void PopulateStockInformation(CommerceStorefront storefront, WishList wishList) { var productList = wishList.Lines.Select(line => new CommerceInventoryProduct { ProductId = line.Product.ProductId, CatalogName = ((CommerceCartProduct)line.Product).ProductCatalog }).ToList(); var stockInfos = this.InventoryManager.GetStockInformation(storefront, productList, StockDetailsLevel.Status).Result; if (stockInfos == null) { return; } foreach (var line in wishList.Lines) { var stockInfo = stockInfos.ToList().FirstOrDefault(si => si.Product.ProductId.Equals(line.Product.ProductId, StringComparison.OrdinalIgnoreCase)); if (stockInfo == null) { continue; } line.Product.StockStatus = new Sitecore.Commerce.Entities.Inventory.StockStatus(Convert.ToInt32((decimal)stockInfo.Properties["OnHandQuantity"]), stockInfo.Status.Name); this.InventoryManager.VisitedProductStockStatus(storefront, stockInfo, string.Empty); } }