public static ProcessedProductFeed ProcessProductFeed(IEnumerable <Product> preProcessProducts, IEnumerable <AccountPrice> accountPrices) { var feed = new ProcessedProductFeed(); foreach (var product in preProcessProducts) { ProcessedProduct processedProduct = ConvertProduct(product); feed.Products.Add(processedProduct); } foreach (var price in accountPrices) { ProcessedAccountPrice processedAccountPrice = ConvertAccountPrice(price); feed.AccountPrices.Add(processedAccountPrice); } return(feed); }
public static List <ProcessedProductDelta> ProcessProductDeltas(IEnumerable <Product> preProcessProducts, IEnumerable <DeletedProductSku> deletedProducts, IEnumerable <AccountPrice> accountPrices, IEnumerable <DeletedAccountPrice> deletedAccountPrices, string accessKey) { var processedProducts = new List <ProcessedProduct>(); var processedAccountPrices = new List <ProcessedAccountPrice>(); foreach (var product in preProcessProducts) { ProcessedProduct processedProduct = ConvertProduct(product); processedProducts.Add(processedProduct); } foreach (var price in accountPrices) { ProcessedAccountPrice processedAccountPrice = ConvertAccountPrice(price); processedAccountPrices.Add(processedAccountPrice); } return(ComposeDeltas.GenerateDeltas(processedProducts, deletedProducts, processedAccountPrices, deletedAccountPrices, accessKey)); }
private static ProcessedProduct ConvertProduct(Product product) { var processedProduct = new ProcessedProduct { AccountExclusions = product.AccountExclusions?.ToArray(), AccountInclusions = product.AccountInclusions?.ToArray(), Brand = product.Brand, Categories = product.Categories.ToArray(), Description = product.Description, ExcludeFromRecommenders = product.ExcludeFromRecommenders, Image = product.Image, ImageOverlay = product.ImageOverlay, Link = product.Link, NewArrival = product.NewArrival, NoDefaultPriceForAccounts = product.NoDefaultPriceForAccounts, OnOffer = product.OnOffer, Sku = product.Sku, Title = product.Title, AssociatedTitles = new[] { product.Title }, Visibility = (int)product.Visibility }; var associatedSkus = new List <string> { product.Sku }; var associatedTitles = new List <string> { product.Title }; var searchTags = product.SearchTags ?? new List <string>(); var prices = product.Prices.Count != 0 ? product.Prices : new List <Price>(); var salePrices = product.SalePrices.Count != 0 ? product.SalePrices : new List <Price>(); var attributes = new Dictionary <string, JToken>(); foreach (var variant in product.Variants) { associatedSkus.Add(variant.Sku); associatedTitles.Add(variant.Title); if (variant.SearchTags != null) { searchTags.AddRange(variant.SearchTags); } prices.AddRange(variant.Prices); salePrices.AddRange(variant.SalePrices); foreach (var attr in variant.Attributes) { var values = attr.Value.Where(val => !string.IsNullOrWhiteSpace(val)).Select((value) => { return(WebUtility.HtmlEncode(value)); }); if (values.Count() > 0) { if (attributes.ContainsKey(WebUtility.HtmlEncode(attr.Key))) { var oldValues = attributes[WebUtility.HtmlEncode(attr.Key)].Select(x => x.ToString()).ToList(); attributes[WebUtility.HtmlEncode(attr.Key)] = new JArray(oldValues.Concat(values).Distinct()); } else { attributes.Add(WebUtility.HtmlEncode(attr.Key), new JArray(values)); } } } } processedProduct.AssociatedSkus = associatedSkus.ToArray(); processedProduct.AssociatedTitles = associatedTitles.ToArray(); processedProduct.SearchTags = searchTags.ToArray(); processedProduct.Prices = ProcessPrices(prices); processedProduct.SalePrices = ProcessPrices(salePrices); foreach (var attr in product.Attributes) { var values = attr.Value.Where(val => !string.IsNullOrWhiteSpace(val)).Select((value) => { return(WebUtility.HtmlEncode(value)); }); if (values.Count() > 0) { if (attributes.ContainsKey(WebUtility.HtmlEncode(attr.Key))) { var oldValues = attributes[WebUtility.HtmlEncode(attr.Key)].Select(x => x.ToString()).ToList(); attributes[WebUtility.HtmlEncode(attr.Key)] = new JArray(oldValues.Concat(values).Distinct()); } else { attributes.Add(WebUtility.HtmlEncode(attr.Key), new JArray(values)); } } } processedProduct.Attributes = attributes; return(processedProduct); }