public static IList <ExcelWFSProductUSViewModel> GenerateToExcelUS(IUnitOfWork db, IBarcodeService barcodeService, IMarketCategoryService categoryService, StyleViewModel model, DateTime when, out string filename) { /* * 1. Item_sku: * a. First row = Style * b. Other rows – Style-%size%, i.e. K123123-2T, K123123-3T.. * 2. Item name: * a. First Raw - %Name% + “,”+%Size Group% (Infant, Toddler, Kids)+”Sizes”+%Size_Range%” (example: Planes Boys 'Turn Up the Heat' Coat Style Pajama Set, Toddler Sizes 2T-4T) * b. Other rows: %Name% + “,”+%Size Group% (Infant, Toddler, Kids)+%Size% (i.e. Planes Boys 'Turn Up the Heat' Coat Style Pajama Set, Toddler Size 2T) * 3. external_product_id – barcode (empty for first raw) * 4. external_product_id_type – harcoded “UPC” (empty for first raw) * 16. brand_name - Main License * 17. item_type – use same logic as you use when you generate xls from ASIN * 18. main_image_url – upload image to server, and insert public URL to this image here * 19. Color - %Color% * 20. Department_name - use same logic as you use when you generate xls from ASIN * 21. Size - %size% * 22. update_delete – “Update” * 23. standard_price - %price% * 24. list_price -- %MSRP% * 25. currency – “USD” * 26. quantity – “%Quantity% * 27. bullet_point1 – “Authentic ”+ %Main License% +” product with reliable quality and durability * 28. bullet_point2 – “Featuring “+%sublicense% * 29. bullet_point3 – if(Material != Cotton) “Flame resistant” else “100% Cotton” * 30. bullet_point4 – “Machine Wash, Easy Care” * 31. generic_keywords1 = if(Item style = pajama) “ sleepwear, pj, jummie, new, %sleeve%” * if(nightgown) “night, gown, night-gown, sleepwear, pj, jummie, new, %sleeve%, dress up” * 32. “Gift, present, 2015, cozy ” If(Material =fleece) “Fleece, microfleece, warm, winter spring” * 33. parent_child, parent_sku, relationship_type, variation_theme – same logic as you use when you generate xls from ASIN * 34. if More then one picture provided insert their URL into other_image_url1, other_image_url2, other_image_url3 */ var models = new List <ExcelWFSProductUSViewModel>(); var parent = new ExcelWFSProductUSViewModel(); var childs = new List <ExcelWFSProductUSViewModel>(); var sizes = model.StyleItems.Items; //Size Group, Size Range var hasKids2 = sizes.Any(s => ItemExportHelper.GetSizeGroupByName(s.SizeGroupName, true) == ExportSizeGroup.Kids2); ExportSizeGroup?sizeGroup = sizes.Any() ? (ExportSizeGroup?)ItemExportHelper.GetSizeGroupByName(sizes.Last().SizeGroupName, false) : null; var sizeGroupName = ItemExportHelper.GetSizeGroupName(sizeGroup); var sizeRange = ItemExportHelper.GetSizeRangeName(sizes.Select(s => s.Size).ToList(), hasKids2); var firstSize = sizes.Any() ? sizes[0].Size : String.Empty; //Features Values var features = model.Features.Select(f => new FeatureValueDTO() { FeatureId = f.FeatureId, Value = f.Value, }).ToList(); var allFeatureValues = db.FeatureValues.GetAllFeatureValueByItemType(1); var gender = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.GENDER); var itemStyle = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.ITEMSTYLE); var sleeve = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SLEEVE); var material = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MATERIAL); var color1 = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.COLOR1); var mainLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MAIN_LICENSE); var subLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SUB_LICENSE1); //var shippingSize = ItemExportHelper.GetFeatureValue(features, allFeatureValues, Feature.SHIPPING_SIZE); //var itemType = ItemExportHelper.GetItemType(itemStyle); var sizeType = ItemExportHelper.GetSizeType(firstSize); var categoryInfo = categoryService.GetCategory(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId, itemStyle, gender, sizeType); var brandName = ItemExportHelper.GetBrandName(mainLicense, subLicense); var newItemType = categoryInfo.Key1;// ItemExportHelper.ItemTypeConverter(firstSize ?? "", itemType, itemStyle, gender); var newDepartment = StringHelper.GetFirstNotEmpty(categoryInfo.Key2, ItemExportHelper.DepartmentConverter(gender, newItemType, sizeType)); string clothingType = categoryInfo.Key3; var searchTerms = model.SearchTerms; // ItemExportHelper.BuildSearchTerms(itemStyle, material, sleeve); var keyFeatures = model.GetBulletPoints(); // ItemExportHelper.BuildKeyFeatures(mainLicense, subLicense, material); //-------------------------- //Parent item //-------------------------- parent.SKU = model.StyleId; parent.ASIN = ""; parent.Title = model.Name + "," + (!String.IsNullOrEmpty(sizeGroupName) ? " " + ItemExportHelper.FormatSizeGroupName(sizeGroupName) : String.Empty) + " " + sizeRange; //If it causes name length to exceed maximum allowed, please drop words “Kids” or Toddler” var inlcudeSizeGroup = true; if (parent.Title.Length > ItemExportHelper.MaxItemNameLength) { parent.Title = model.Name + ", " + sizeRange; inlcudeSizeGroup = false; } parent.ProductId = ""; parent.BrandName = brandName; parent.Type = newItemType; var images = new List <string>(); var swatchImage = ""; if (model.ImageSet != null) { images = model.ImageSet.Images .Where(im => im.Category != (int)StyleImageCategories.Swatch) .OrderByDescending(im => ImageHelper.GetSortIndex(im.Category)) .ThenByDescending(im => im.IsDefault) .ThenBy(im => im.Id) .Select(im => im.ImageUrl) .ToList(); swatchImage = model.ImageSet.Images .FirstOrDefault(im => im.Category == (int)StyleImageCategories.Swatch)?.ImageUrl; parent.MainImageURL = images.Count > 0 ? images[0] : ""; parent.OtherImageUrl1 = images.Count > 1 ? images[1] : ""; parent.OtherImageUrl2 = images.Count > 2 ? images[2] : ""; parent.OtherImageUrl3 = images.Count > 3 ? images[3] : ""; parent.SwatchImageUrl = swatchImage; } parent.Color = "";// color1; parent.Department = newDepartment; parent.Size = ""; parent.Description = model.Description; parent.Update = "Update"; parent.StandardPrice = ""; parent.SuggestedPrice = Math.Round(model.MSRP).ToString("G"); parent.Currency = "USD"; parent.Quantity = ""; parent.KeyProductFeatures1 = keyFeatures.Count > 0 ? keyFeatures[0] : ""; parent.KeyProductFeatures2 = keyFeatures.Count > 1 ? keyFeatures[1] : ""; parent.KeyProductFeatures3 = keyFeatures.Count > 2 ? keyFeatures[2] : ""; parent.KeyProductFeatures4 = keyFeatures.Count > 3 ? keyFeatures[3] : ""; parent.KeyProductFeatures5 = keyFeatures.Count > 4 ? keyFeatures[4] : ""; parent.SearchTerms1 = searchTerms; //parent.SearchTerms3 = ""; //parent.SearchTerms4 = ""; //parent.SearchTerms5 = ""; parent.Parentage = "Parent"; parent.ParentSKU = ""; parent.RelationshipType = ""; parent.VariationTheme = "Size"; parent.FeedProductType = clothingType; //-------------------------- //Child items //-------------------------- foreach (var size in sizes) { var child = new ExcelWFSProductUSViewModel(); child.SKU = model.StyleId + "-" + ItemExportHelper.ConvertSizeForStyleId(size.Size, hasKids2); child.StyleItemId = size.Id; child.StyleId = model.Id; if (size.AutoGeneratedBarcode) { var newBarcode = BarcodeHelper.GenerateBarcode(barcodeService, child.SKU, when); if (!String.IsNullOrEmpty(newBarcode)) { if (size.Barcodes == null) { size.Barcodes = new List <BarcodeDTO>(); } size.Barcodes.Insert(0, new BarcodeDTO() { Barcode = newBarcode }); } } child.ASIN = (size.Barcodes != null && size.Barcodes.Any()) ? size.Barcodes.FirstOrDefault().Barcode : String.Empty; child.Title = model.Name + "," + (inlcudeSizeGroup ? " " + ItemExportHelper.FormatSizeGroupName(size.SizeGroupName) : "") + " Size " + ItemExportHelper.ConvertSizeForItemName(size.Size, hasKids2); child.ProductId = "UPC"; child.BrandName = brandName; child.Type = newItemType; child.MainImageURL = images.Count > 0 ? images[0] : ""; child.OtherImageUrl1 = images.Count > 1 ? images[1] : ""; child.OtherImageUrl2 = images.Count > 2 ? images[2] : ""; child.OtherImageUrl3 = images.Count > 3 ? images[3] : ""; child.SwatchImageUrl = swatchImage; child.Color = ItemExportHelper.PrepareColor(String.IsNullOrEmpty(size.Color) ? color1 : size.Color); child.Department = newDepartment; child.Size = size.Size; child.Description = model.Description; child.Update = "Update"; child.StandardPrice = model.Price.ToString("G"); child.SuggestedPrice = Math.Round(model.MSRP).ToString("G"); child.Currency = "USD"; child.Quantity = size.Quantity.ToString(); child.KeyProductFeatures1 = parent.KeyProductFeatures1; child.KeyProductFeatures2 = parent.KeyProductFeatures2; child.KeyProductFeatures3 = parent.KeyProductFeatures3; child.KeyProductFeatures4 = parent.KeyProductFeatures4; child.KeyProductFeatures5 = parent.KeyProductFeatures5; child.SearchTerms1 = parent.SearchTerms1; //child.SearchTerms1 = parent.SearchTerms1; //child.SearchTerms2 = parent.SearchTerms2; //child.SearchTerms3 = parent.SearchTerms3; //child.SearchTerms4 = parent.SearchTerms4; //child.SearchTerms5 = parent.SearchTerms5; child.Parentage = "Child"; child.ParentSKU = parent.SKU; child.RelationshipType = "Variation"; child.VariationTheme = "Size"; child.FeedProductType = clothingType; childs.Add(child); } models.Add(parent); models.AddRange(childs); filename = model.StyleId + "_" + subLicense; filename = filename.Replace(" ", "") + "_US.xls"; return(models); }
public static IList <ItemVariationExportViewModel> CreateStyleVariations(IUnitOfWork db, string styleString, IList <ItemSizeMapping> existSizeMapping, MarketType market, string marketplaceId) { var results = new List <ItemVariationExportViewModel>(); var style = db.Styles.GetActiveByStyleIdAsDto(styleString); if (style == null) { return(results); } var styleMainLicenseDto = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(style.Id, StyleFeatureHelper.MAIN_LICENSE); var styleSubLicenseDto = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(style.Id, StyleFeatureHelper.SUB_LICENSE1); var styleMainLicense = styleMainLicenseDto != null ? styleMainLicenseDto.Value : null; var styleSubLicense = styleSubLicenseDto != null ? styleSubLicenseDto.Value : null; var styleItems = db.StyleItems .GetByStyleIdWithBarcodesAsDto(style.Id) .OrderBy(o => SizeHelper.GetSizeIndex(o.Size)) .ToList(); var forceReplace = styleItems.Any(s => (s.Size ?? "").Contains("/")); foreach (var styleItem in styleItems) { var newItem = new ItemVariationExportViewModel(); var index = 0; var baseSKU = style.StyleID + "-" + SizeHelper.PrepareSizeForSKU(styleItem.Size, forceReplace); while (db.Listings.CheckForExistenceSKU(SkuHelper.SetSKUMiddleIndex(baseSKU, index), (MarketType)market, marketplaceId)) { index++; } newItem.IsSelected = true; newItem.SKU = SkuHelper.SetSKUMiddleIndex(baseSKU, index); newItem.StyleId = styleItem.StyleId; newItem.StyleString = style.StyleID; newItem.StyleItemId = styleItem.StyleItemId; newItem.StyleColor = styleItem.Color; newItem.StyleSize = styleItem.Size; newItem.BrandName = ItemExportHelper.GetBrandName(styleMainLicense, styleSubLicense); newItem.Size = SizeHelper.PrepareSizeForExport(db, newItem.StyleSize, existSizeMapping); if (styleItem.Barcodes != null) { foreach (var barcode in styleItem.Barcodes) { if (!String.IsNullOrEmpty(barcode.Barcode) && !db.Items.CheckForExistenceBarcode(barcode.Barcode, market, marketplaceId)) { newItem.Barcode = barcode.Barcode; break; } } } if (String.IsNullOrEmpty(newItem.Barcode)) { newItem.AutoGeneratedBarcode = true; } results.Add(newItem); } return(results); }
public static IList <ExcelProductWalmartViewModel> GenerateToExcelWalmart(IUnitOfWork db, IBarcodeService barcodeService, StyleViewModel model, DateTime when, out string filename) { var models = new List <ExcelProductWalmartViewModel>(); var childs = new List <ExcelProductWalmartViewModel>(); var sizes = model.StyleItems.Items; //Size Group, Size Range var hasKids2 = sizes.Any(s => ItemExportHelper.GetSizeGroupByName(s.SizeGroupName, true) == ExportSizeGroup.Kids2); ExportSizeGroup?sizeGroup = sizes.Any() ? (ExportSizeGroup?)ItemExportHelper.GetSizeGroupByName(sizes.Last().SizeGroupName, false) : null; var sizeGroupName = ItemExportHelper.GetSizeGroupName(sizeGroup); var sizeRange = ItemExportHelper.GetSizeRangeName(sizes.Select(s => s.Size).ToList(), hasKids2); var firstSize = sizes.Any() ? sizes[0].Size : String.Empty; //Features Values var features = model.Features.Select(f => new FeatureValueDTO() { FeatureId = f.FeatureId, Value = f.Value, }).ToList(); var allFeatureValues = db.FeatureValues.GetAllFeatureValueByItemType(1); var gender = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.GENDER); var itemStyle = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.ITEMSTYLE); var sleeve = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SLEEVE); var material = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MATERIAL); var color1 = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.COLOR1); var mainLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MAIN_LICENSE); var subLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SUB_LICENSE1); //var shippingSize = ItemExportHelper.GetFeatureValue(features, allFeatureValues, Feature.SHIPPING_SIZE); //var itemType = ItemExportHelper.GetItemType(itemStyle); var brandName = ItemExportHelper.GetBrandName(mainLicense, subLicense); //var newItemType = ItemExportHelper.ItemTypeConverter(firstSize ?? "", itemType, itemStyle, gender); //var newDepartment = ItemExportHelper.DepartmentConverter(newItemType, gender, firstSize); var searchTerms = model.SearchTerms; // ItemExportHelper.BuildSearchTerms(itemStyle, material, sleeve); var keyFeatures = model.GetBulletPoints(); // ItemExportHelper.BuildKeyFeatures(mainLicense, subLicense, material); ////-------------------------- ////Parent item ////-------------------------- //parent.SKU = model.StyleId; //parent.ASIN = ""; //parent.Title = model.Name // + (!String.IsNullOrEmpty(sizeGroupName) ? ", " + ItemExportHelper.FormatSizeGroupName(sizeGroupName) : String.Empty) // + " " + sizeRange; //parent.ProductId = ""; //parent.BrandName = brandName; //parent.Type = newItemType; //if (model.ImageSet != null) //{ // parent.MainImageURL = model.ImageSet.Image1Url; // parent.OtherImageUrl1 = model.ImageSet.Image2Url; // parent.OtherImageUrl2 = model.ImageSet.Image3Url; // parent.OtherImageUrl3 = model.ImageSet.Image4Url; //} //parent.Color = "";// color1; //parent.Department = newDepartment; //parent.Size = ""; //parent.Description = model.Description; //parent.Update = "Update"; //parent.StandardPrice = ""; //parent.SuggestedPrice = model.MSRP.ToString("G"); //parent.Currency = "USD"; //parent.Quantity = ""; //parent.KeyProductFeatures1 = keyFeatures.Count > 0 ? keyFeatures[0] : ""; //parent.KeyProductFeatures2 = keyFeatures.Count > 1 ? keyFeatures[1] : ""; //parent.KeyProductFeatures3 = keyFeatures.Count > 2 ? keyFeatures[2] : ""; //parent.KeyProductFeatures4 = keyFeatures.Count > 3 ? keyFeatures[3] : ""; //parent.KeyProductFeatures5 = keyFeatures.Count > 4 ? keyFeatures[4] : ""; //parent.SearchTerms1 = searchTerms; ////parent.SearchTerms3 = ""; ////parent.SearchTerms4 = ""; ////parent.SearchTerms5 = ""; //parent.Parentage = "Parent"; //parent.ParentSKU = ""; //parent.RelationshipType = ""; //parent.VariationTheme = "Size"; //-------------------------- //Child items //-------------------------- foreach (var size in sizes) { var child = new ExcelProductWalmartViewModel(); child.SKU = model.StyleId + "-" + ItemExportHelper.ConvertSizeForStyleId(size.Size, hasKids2); if (size.AutoGeneratedBarcode) { var newBarcode = BarcodeHelper.GenerateBarcode(barcodeService, child.SKU, when); if (!String.IsNullOrEmpty(newBarcode)) { if (size.Barcodes == null) { size.Barcodes = new List <BarcodeDTO>(); } size.Barcodes.Insert(0, new BarcodeDTO() { Barcode = newBarcode }); } } child.ProductIdType = "UPC"; child.ProductId = (size.Barcodes != null && size.Barcodes.Any()) ? size.Barcodes.FirstOrDefault().Barcode : String.Empty; child.Title = model.Name + ", " + ItemExportHelper.FormatSizeGroupName(size.SizeGroupName) + " Size " + ItemExportHelper.ConvertSizeForItemName(size.Size, hasKids2); child.LongDescription = String.IsNullOrEmpty(model.Description) ? child.Title : model.Description; child.ShortDescription = String.IsNullOrEmpty(model.Description) ? child.Title : model.Description; child.ShelfDescription = String.IsNullOrEmpty(model.Description) ? child.Title : model.Description; child.Brand = brandName; if (model.ImageSet != null) { child.MainImageUrl = model.ImageSet.Image1Url; //child.OtherImageUrl1 = model.ImageSet.Image2Url; //child.OtherImageUrl2 = model.ImageSet.Image3Url; //child.OtherImageUrl3 = model.ImageSet.Image4Url; } child.MainImageAltText = child.Title; child.Color = ItemExportHelper.PrepareColor(String.IsNullOrEmpty(size.Color) ? color1 : size.Color); child.ClothingSize = size.Size; child.PriceCurrency = "USD"; child.PriceAmount = 99.99M; //TODO: price child.MinAdvertisedPriceAmount = child.PriceAmount; child.MinAdvertisedPriceCurrency = child.PriceCurrency; child.VariantGroupId = model.StyleId; child.VariantAttributeNames = "ClothingSize"; //TODO: add optional Color child.ProductTaxCode = "2038345"; child.ShippingWeightValue = size.Weight.ToString(); child.ShippingWeightUnit = "OZ"; childs.Add(child); } models.AddRange(childs); filename = model.StyleId + "_" + subLicense; filename = filename.Replace(" ", "") + "_Walmart" + Path.GetExtension(TemplatePath); return(models); }
public static IList <ExcelProductUKViewModel> GenerateToExcelUK(IUnitOfWork db, IBarcodeService barcodeService, IMarketCategoryService categoryService, StyleViewModel model, DateTime when, out string filename) { var gbpExchangeRate = PriceHelper.GBPtoUSD; var models = new List <ExcelProductUKViewModel>(); var parent = new ExcelProductUKViewModel(); var childs = new List <ExcelProductUKViewModel>(); var sizes = model.StyleItems.Items; //Size Group, Size Range var hasKids2 = sizes.Any(s => ItemExportHelper.GetSizeGroupByName(s.SizeGroupName, true) == ExportSizeGroup.Kids2); ExportSizeGroup?sizeGroup = sizes.Any() ? (ExportSizeGroup?)ItemExportHelper.GetSizeGroupByName(sizes.Last().SizeGroupName, false) : null; var sizeGroupName = ItemExportHelper.GetSizeGroupName(sizeGroup); var sizeRange = ItemExportHelper.GetSizeRangeName(sizes.Select(s => s.Size).ToList(), hasKids2); var firstSize = sizes.Any() ? sizes[0].Size : String.Empty; //Features Values var features = model.Features.Select(f => new FeatureValueDTO() { FeatureId = f.FeatureId, Value = f.Value, }).ToList(); var allFeatureValues = db.FeatureValues.GetAllFeatureValueByItemType(1); var gender = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.GENDER); var itemStyle = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.ITEMSTYLE); var sleeve = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SLEEVE); var material = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MATERIAL); var color1 = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.COLOR1); var mainLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MAIN_LICENSE); var subLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SUB_LICENSE1); //var shippingSize = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SHIPPING_SIZE); var materialComposition = ItemExportHelper.GetFeatureTextValue(features, StyleFeatureHelper.MATERIAL_COMPOSITION); var sizeType = ItemExportHelper.GetSizeType(firstSize); var categoryInfo = categoryService.GetCategory(MarketType.AmazonEU, MarketplaceKeeper.AmazonUkMarketplaceId, itemStyle, gender, sizeType); //var itemType = ItemExportHelper.GetItemType(itemStyle); var brandName = ItemExportHelper.GetBrandName(mainLicense, subLicense); var newItemType = categoryInfo.Key1;// ItemExportHelper.ItemTypeConverter(firstSize ?? "", itemType, itemStyle, gender); var newDepartment = StringHelper.GetFirstNotEmpty(categoryInfo.Key2, ItemExportHelper.DepartmentConverter(gender, newItemType, sizeType)); var searchTerms = model.SearchTerms; // ItemExportHelper.BuildSearchTerms(itemStyle, material, sleeve); var keyFeatures = model.GetBulletPoints(); // ItemExportHelper.BuildKeyFeatures(mainLicense, subLicense, material); var hasCotton = StringHelper.GetInOneOfStrings("Cotton", new List <string>() { searchTerms, model.Name, model.Description, material }); if (String.IsNullOrEmpty(materialComposition)) { if (hasCotton) { materialComposition = "Cotton"; } else { materialComposition = "Polyester"; } } //-------------------------- //Parent item //-------------------------- parent.SKU = model.StyleId; parent.ASIN = ""; parent.Title = model.Name + "," + (!String.IsNullOrEmpty(sizeGroupName) ? " " + ItemExportHelper.FormatSizeGroupName(sizeGroupName) : String.Empty) + " " + sizeRange; //If it causes name length to exceed maximum allowed, please drop words “Kids” or Toddler” var inlcudeSizeGroup = true; if (parent.Title.Length > ItemExportHelper.MaxItemNameLength) { parent.Title = model.Name + ", " + sizeRange; inlcudeSizeGroup = false; } parent.ProductId = ""; parent.BrandName = brandName; parent.ClothingType = "sleepwear"; // = newItemType; var images = new List <string>(); var swatchImage = ""; if (model.ImageSet != null) { images = model.ImageSet.Images .Where(im => im.Category != (int)StyleImageCategories.Swatch) .OrderByDescending(im => ImageHelper.GetSortIndex(im.Category)) .ThenByDescending(im => im.IsDefault) .ThenBy(im => im.Id) .Select(im => im.ImageUrl) .ToList(); swatchImage = model.ImageSet.Images .FirstOrDefault(im => im.Category == (int)StyleImageCategories.Swatch)?.ImageUrl; parent.MainImageURL = images.Count > 0 ? images[0] : ""; parent.OtherImageUrl1 = images.Count > 1 ? images[1] : ""; parent.OtherImageUrl2 = images.Count > 2 ? images[2] : ""; parent.OtherImageUrl3 = images.Count > 3 ? images[3] : ""; //parent.SwatchImageUrl = swatchImage; } parent.Color = ""; parent.Department = newDepartment; parent.Size = ""; parent.MaterialComposition = materialComposition; parent.Description = model.Description; parent.Update = "Update"; parent.StandardPrice = ""; //parent.SuggestedPrice = model.MSRP.ToString("G"); parent.Currency = "GBP"; parent.Quantity = ""; parent.RecommendedBrowseNodes1 = ExcelProductUKViewModel.GetRecommendedBrowseNodes1(newDepartment, firstSize, newItemType); parent.SearchTerms1 = searchTerms; parent.KeyProductFeatures1 = keyFeatures.Count > 0 ? keyFeatures[0] : ""; parent.KeyProductFeatures2 = keyFeatures.Count > 1 ? keyFeatures[1] : ""; parent.KeyProductFeatures3 = keyFeatures.Count > 2 ? keyFeatures[2] : ""; parent.KeyProductFeatures4 = keyFeatures.Count > 3 ? keyFeatures[3] : ""; parent.KeyProductFeatures5 = keyFeatures.Count > 4 ? keyFeatures[4] : ""; parent.Parentage = "Parent"; parent.ParentSKU = ""; parent.RelationshipType = ""; parent.VariationTheme = "Size"; //-------------------------- //Child items //-------------------------- foreach (var size in sizes) { var child = new ExcelProductUKViewModel(); child.SKU = model.StyleId + "-" + ItemExportHelper.ConvertSizeForStyleId(size.Size, hasKids2); if (size.AutoGeneratedBarcode) { var newBarcode = BarcodeHelper.GenerateBarcode(barcodeService, child.SKU, when); if (!String.IsNullOrEmpty(newBarcode)) { if (size.Barcodes == null) { size.Barcodes = new List <BarcodeDTO>(); } size.Barcodes.Insert(0, new BarcodeDTO() { Barcode = newBarcode }); } } child.UPC = (size.Barcodes != null && size.Barcodes.Any()) ? size.Barcodes.FirstOrDefault().Barcode : String.Empty; child.Title = model.Name + "," + (inlcudeSizeGroup ? " " + ItemExportHelper.FormatSizeGroupName(size.SizeGroupName) : "") + " Size " + ItemExportHelper.ConvertSizeForItemName(size.Size, hasKids2); child.ProductId = "UPC"; child.BrandName = brandName; child.ClothingType = "sleepwear";// newItemType; child.MainImageURL = images.Count > 0 ? images[0] : ""; child.OtherImageUrl1 = images.Count > 1 ? images[1] : ""; child.OtherImageUrl2 = images.Count > 2 ? images[2] : ""; child.OtherImageUrl3 = images.Count > 3 ? images[3] : ""; //child.SwatchImageUrl = swatchImage; child.Color = ItemExportHelper.PrepareColor(String.IsNullOrEmpty(size.Color) ? color1 : size.Color); child.Department = newDepartment; child.Size = ExcelProductUKViewModel.SizeConverter(size.Size, material); child.MaterialComposition = materialComposition; child.Description = model.Description; child.Update = "Update"; child.StandardPrice = PriceHelper.Convert(model.Price, gbpExchangeRate, true).ToString("G"); //child.SuggestedPrice = model.MSRP.ToString("G"); child.Currency = "GBP"; child.Quantity = size.Quantity.ToString(); child.RecommendedBrowseNodes1 = ExcelProductUKViewModel.GetRecommendedBrowseNodes1(newDepartment, child.Size, newItemType); child.KeyProductFeatures1 = parent.KeyProductFeatures1; child.KeyProductFeatures2 = parent.KeyProductFeatures2; child.KeyProductFeatures3 = parent.KeyProductFeatures3; child.KeyProductFeatures4 = parent.KeyProductFeatures4; child.KeyProductFeatures5 = parent.KeyProductFeatures5; child.SearchTerms1 = parent.SearchTerms1; //child.SearchTerms2 = parent.SearchTerms2; //child.SearchTerms3 = parent.SearchTerms3; //child.SearchTerms4 = parent.SearchTerms4; //child.SearchTerms5 = parent.SearchTerms5; child.Parentage = "Child"; child.ParentSKU = parent.SKU; child.RelationshipType = "Variation"; child.VariationTheme = "Size"; childs.Add(child); } models.Add(parent); models.AddRange(childs); filename = model.StyleId + "_" + subLicense; filename = filename.Replace(" ", "") + "_UK.xls"; return(models); //ExcelHelper.ExportIntoFile(HttpContext.Current.Server.MapPath(UKTemplatePath), models); }
public void FindListingsPositionInSearch() { var results = new List <StylePositionOnWM>(); using (var db = _dbFactory.GetRWDb()) { var openApi = new WalmartOpenApi(_log, "trn9fdghvb8p9gjj9j6bvjwx"); var wmItems = db.Items.GetAll().Where(i => i.ItemPublishedStatus == (int)PublishedStatuses.Published && i.Market == (int)MarketType.Walmart).ToList(); var styleIdList = wmItems.Where(i => i.StyleId.HasValue).Select(i => i.StyleId.Value).ToList(); //var styleList = db.Styles.GetAll().Where(st => styleIdList.Contains(st.Id)).ToList(); var groupByStyle = from siCache in db.StyleItemCaches.GetAll() group siCache by siCache.StyleId into byStyle select new { StyleId = byStyle.Key, OneHasStrongQty = byStyle.Any(s => s.RemainingQuantity > 20), //NOTE: >20 Qty = byStyle.Sum(s => s.RemainingQuantity) }; var styleList = (from s in db.Styles.GetAll() join sCache in db.StyleCaches.GetAll() on s.Id equals sCache.Id join qty in groupByStyle on s.Id equals qty.StyleId where styleIdList.Contains(s.Id) orderby qty.Qty descending select s) .Take(100) .ToList(); var mainLicenseFeatures = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(styleIdList, new[] { StyleFeatureHelper.MAIN_LICENSE }).ToList(); var subLicenseFeatures = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(styleIdList, new[] { StyleFeatureHelper.SUB_LICENSE1 }).ToList(); var itemStyleFeatures = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(styleIdList, new[] { StyleFeatureHelper.ITEMSTYLE }).ToList(); var resultsCache = new Dictionary <string, IList <OpenItem> >(); foreach (var style in styleList) { var mainLicenseFeature = mainLicenseFeatures.FirstOrDefault(f => f.StyleId == style.Id); var subLicenseFeature = subLicenseFeatures.FirstOrDefault(f => f.StyleId == style.Id); var itemStyleFeature = itemStyleFeatures.FirstOrDefault(f => f.StyleId == style.Id); var brandName = ItemExportHelper.GetBrandName(mainLicenseFeature?.Value, subLicenseFeature?.Value); var manufacture = brandName; if (String.IsNullOrEmpty(manufacture)) { manufacture = style.Manufacturer; } var itemStyle = itemStyleFeature?.Value ?? "Pajamas"; itemStyle = itemStyle.Replace("– 2pc", "").Replace("– 3pc", "").Replace("– 4pc", "").Trim(); var keywords = StringHelper.JoinTwo(" ", manufacture, itemStyle); _log.Info("Searching: " + keywords); IList <OpenItem> foundItems = new List <OpenItem>(); if (resultsCache.ContainsKey(keywords)) { foundItems = resultsCache[keywords]; } else { var searchResult = openApi.SearchProducts(keywords, WalmartUtils.ApparelCategoryId, null, null, 1, 100); if (searchResult.IsSuccess) { foundItems = searchResult.Data; resultsCache.Add(keywords, searchResult.Data); } } int? position = null; string positionItemId = null; string buyBoxWinner = null; var itemsByStyle = wmItems.Where(i => i.StyleId == style.Id).ToList(); var itemIds = itemsByStyle.Where(i => !String.IsNullOrEmpty(i.SourceMarketId)).Select(i => i.SourceMarketId).ToList(); for (int i = 0; i < foundItems.Count; i++) { if (itemIds.Contains(foundItems[i].ItemId) && position == null) { position = i + 1; positionItemId = foundItems[i].ItemId; buyBoxWinner = foundItems[i].SellerInfo; } } _log.Info(style.StyleID + ", position: " + position + ", " + keywords + ", " + buyBoxWinner + ", " + positionItemId); results.Add(new StylePositionOnWM() { StyleId = style.Id, StyleString = style.StyleID, SearchKeywords = keywords, RequestedSearchResults = foundItems.Count, BestPosition = position, BuyBoxWinner = buyBoxWinner, BestPositionUrl = !String.IsNullOrEmpty(positionItemId) ? String.Format("https://www.walmart.com/ip/item/{0}", positionItemId) : "" }); } } var filename = "WMListingPositions_" + DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + ".xls"; var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename); var b = new ExportColumnBuilder <StylePositionOnWM>(); var columns = new List <ExcelColumnInfo>() { b.Build(p => p.StyleString, "Style Id", 25), b.Build(p => p.SearchKeywords, "Search Keywords", 25), b.Build(p => p.RequestedSearchResults, "Requested search results", 35), b.Build(p => p.BestPosition, "Best Position", 15), b.Build(p => p.BuyBoxWinner, "Buy Box Winner", 20), b.Build(p => p.BestPositionUrl, "Best Position Url", 45) }; using (var stream = ExcelHelper.Export(results, columns)) { stream.Seek(0, SeekOrigin.Begin); using (var fileStream = File.Create(filepath)) { stream.CopyTo(fileStream); } } }