public ShopifyProduct(string handle, string title, string details, string vendor, string type, string[] tags, ShopifyProductOptions options, ShopifyVariant variant, string imageSource) { Handle = handle; Title = title; Details = details; Vendor = vendor; Type = type; Tags = tags; Variant = variant; Options = options; ImageSource = imageSource; }
private Dictionary <string, ShopifyProduct> csvToShopifyData(IEnumerable <char> csv) { var shopifyData = new Dictionary <string, ShopifyProduct>(); foreach (var line in csvLineToArray(csv)) { var shopifyProductOptions = new ShopifyProductOptions(line[6], line[7], line[8], line[9], line[10], line[11]); var shopifyVariant = new ShopifyVariant(line[12], line[13], line[14], line[15], line[16], line[17], line[18], line[17], line[18], line[19]); var product = new ShopifyProduct(line[0], line[1], line[2], line[3], line[4], line[5].Split(','), shopifyProductOptions, shopifyVariant, line[line.Length - 1]); shopifyData.Add(product.Handle, product); } return(shopifyData); }
private static ShopifyImportData getImportData(string file) { var details = new List <string>(); var description = new List <string>(); var variants = new List <Tuple <ShopifyProductOptions, ShopifyVariant> >(); var foundDesc = false; using (var reader = new StreamReader(file)) { string line; while ((line = reader.ReadLine()) != null) { if (line.ToLower().Contains(Description)) { foundDesc = true; } if (foundDesc && !line.ToLower().Contains(Description)) { description.Add(line); } else { details.Add(line); } } } var url = details.Where(s => s.IndexOf(Url, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(url)) { url = Regex.Replace(url, Url, "", RegexOptions.IgnoreCase).Trim(); } var vendor = details.Where(s => s.IndexOf(Vendor, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(vendor)) { vendor = Regex.Replace(vendor, Vendor, "", RegexOptions.IgnoreCase).Trim(); } var type = details.Where(s => s.IndexOf(Type, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(type)) { type = Regex.Replace(type, Type, "", RegexOptions.IgnoreCase).Trim(); } var tags = details.Where(s => s.IndexOf(Tags, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(tags)) { tags = Regex.Replace(tags, Tags, "", RegexOptions.IgnoreCase).Trim(); } var price = details.Where(s => s.IndexOf(Price, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(price)) { price = Regex.Replace(price, Price, "", RegexOptions.IgnoreCase).Trim(); var variant = new ShopifyVariant(string.Empty, "0", string.Empty, "1", "deny", "manual", price, string.Empty, "TRUE", "TRUE"); var productOption = new ShopifyProductOptions("Title", "Default Title", string.Empty, string.Empty, string.Empty, string.Empty); variants.Add(new Tuple <ShopifyProductOptions, ShopifyVariant>(productOption, variant)); } foreach (var variant in details.Where(s => s.IndexOf(Variant, StringComparison.OrdinalIgnoreCase) >= 0)) { var vals = Regex.Replace(variant, Variant, "", RegexOptions.IgnoreCase).Trim().Split(','); if (vals.Length > 1) { var v = new ShopifyVariant(string.Empty, "0", string.Empty, "1", "deny", "manual", vals[1].Trim(), string.Empty, "TRUE", "TRUE"); var productOption = new ShopifyProductOptions("Title", vals[0].Trim(), string.Empty, string.Empty, string.Empty, string.Empty); variants.Add(new Tuple <ShopifyProductOptions, ShopifyVariant>(productOption, v)); } } string descriptionHeader = null; if (description.Count > 0 && !description[0].Contains("{{")) { descriptionHeader = description[0]; description.RemoveAt(0); } var importData = new ShopifyImportData(vendor, type, tags, price, url, descriptionHeader ?? @"Details:", description) { Variants = variants }; return(importData); }
private static ShopifyImportData getImportData(string file) { var details = new List<string>(); var description = new List<string>(); var variants = new List<Tuple<ShopifyProductOptions, ShopifyVariant>>(); var foundDesc = false; using (var reader = new StreamReader(file)) { string line; while ((line = reader.ReadLine()) != null) { if (line.ToLower().Contains(Description)) { foundDesc = true; } if (foundDesc && !line.ToLower().Contains(Description)) { description.Add(line); } else { details.Add(line); } } } var url = details.Where(s => s.IndexOf(Url, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(url)) { url = Regex.Replace(url, Url, "", RegexOptions.IgnoreCase).Trim(); } var vendor = details.Where(s => s.IndexOf(Vendor, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(vendor)) { vendor = Regex.Replace(vendor, Vendor, "", RegexOptions.IgnoreCase).Trim(); } var type = details.Where(s => s.IndexOf(Type, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(type)) { type = Regex.Replace(type, Type, "", RegexOptions.IgnoreCase).Trim(); } var tags = details.Where(s => s.IndexOf(Tags, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(tags)) { tags = Regex.Replace(tags, Tags, "", RegexOptions.IgnoreCase).Trim(); } var price = details.Where(s => s.IndexOf(Price, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault(); if (!string.IsNullOrEmpty(price)) { price = Regex.Replace(price, Price, "", RegexOptions.IgnoreCase).Trim(); var variant = new ShopifyVariant(string.Empty, "0", string.Empty, "1", "deny", "manual", price, string.Empty, "TRUE", "TRUE"); var productOption = new ShopifyProductOptions("Title", "Default Title", string.Empty, string.Empty, string.Empty, string.Empty); variants.Add(new Tuple<ShopifyProductOptions, ShopifyVariant>(productOption, variant)); } foreach (var variant in details.Where(s => s.IndexOf(Variant, StringComparison.OrdinalIgnoreCase) >= 0)) { var vals = Regex.Replace(variant, Variant, "", RegexOptions.IgnoreCase).Trim().Split(','); if (vals.Length > 1) { var v = new ShopifyVariant(string.Empty, "0", string.Empty, "1", "deny", "manual", vals[1].Trim(), string.Empty, "TRUE", "TRUE"); var productOption = new ShopifyProductOptions("Title", vals[0].Trim(), string.Empty, string.Empty, string.Empty, string.Empty); variants.Add(new Tuple<ShopifyProductOptions, ShopifyVariant>(productOption, v)); } } string descriptionHeader = null; if (description.Count > 0 && !description[0].Contains("{{")) { descriptionHeader = description[0]; description.RemoveAt(0); } var importData = new ShopifyImportData(vendor, type, tags, price, url, descriptionHeader ?? @"Details:", description) {Variants = variants}; return importData; }
private Dictionary<string, ShopifyProduct> csvToShopifyData(IEnumerable<char> csv) { var shopifyData = new Dictionary<string, ShopifyProduct>(); foreach(var line in csvLineToArray(csv)) { var shopifyProductOptions = new ShopifyProductOptions(line[6], line[7], line[8], line[9], line[10], line[11]); var shopifyVariant = new ShopifyVariant(line[12], line[13], line[14], line[15], line[16], line[17], line[18], line[17], line[18], line[19]); var product = new ShopifyProduct(line[0], line[1], line[2], line[3], line[4], line[5].Split(','), shopifyProductOptions, shopifyVariant, line[line.Length - 1]); shopifyData.Add(product.Handle, product); } return shopifyData; }