예제 #1
0
        private void importProductData(string path, ShopifyImportData data)
        {
            try
            {
                foreach (var fileName in Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly))
                {
                    if (!ValidExtensions.Contains(Path.GetExtension(fileName).ToLower()))
                    {
                        continue;
                    }

                    var file      = Path.GetFileNameWithoutExtension(fileName);
                    var splitfile = file.Split('+');

                    var title  = file.Replace("_", " ").Replace("+", ", ");
                    var handle = file.ToLower().Replace("+", "-").Replace("_", "-");

                    for (var i = 0; i < data.Variants.Count; i++)
                    {
                        ShopifyProduct product;
                        if (i == 0)
                        {
                            product = new ShopifyProduct(handle, title, buildHtmlDescription(splitfile, data),
                                                         data.Vendor, data.Type, data.Tags, data.Variants[i].Item1,
                                                         data.Variants[i].Item2,
                                                         data.ImageUrl + Path.GetFileName(fileName));
                        }
                        else
                        {
                            product = new ShopifyProduct(handle, string.Empty, string.Empty,
                                                         string.Empty, string.Empty, new string[] {}, data.Variants[i].Item1,
                                                         data.Variants[i].Item2, string.Empty);
                        }

                        if (!_products.ContainsKey(product.Handle))
                        {
                            _products.Add(product.Handle, product);
                        }
                        else if (data.Variants.Count > 1)
                        {
                            var newHandle = handle;
                            var iterator  = 1;
                            while (_products.ContainsKey(newHandle))
                            {
                                newHandle += string.Format("-variant{0}", iterator++);
                            }
                            _products.Add(newHandle, product);
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Problems importing information");
            }
        }
예제 #2
0
        private static string buildHtmlDescription(string[] filename, ShopifyImportData data)
        {
            var builder = string.Empty;

            if (data.Details.Count > 0 && data.Details[0].Contains("{{"))
            {
                foreach (var detail in data.Details)
                {
                    var line = detail.Replace("{{", string.Empty).Replace("}}", string.Empty);
                    if (!string.IsNullOrEmpty(line))
                    {
                        builder += line + '\n';
                    }
                }
            }
            else
            {
                builder += string.Format("<h4>{0}</h4>", data.DetailsHeader);
                builder += '\n';
                builder += "<ul>";
                builder += '\n';
                foreach (var detail in data.Details)
                {
                    var match = Regex.Match(detail, "{\\d+}");
                    if (match != null)
                    {
                        var num = Regex.Match(match.ToString(), "\\d+");
                        int i;
                        if (Int32.TryParse(num.ToString(), out i) && filename.Length >= i)
                        {
                            builder += string.Format("<li>{0}</li>", detail.Replace(match.ToString(), filename[i - 1].Replace("_", " ")));
                        }
                        else
                        {
                            builder += string.Format("<li>{0}</li>", detail);
                        }
                    }
                    else
                    {
                        builder += string.Format("<li>{0}</li>", detail);
                    }

                    builder += '\n';
                }
                builder += "</ul>";
            }

            builder = builder.Replace("\"", "\"\"");

            return(builder);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public void ImportDataFromImages(string path, ShopifyImportData data)
 {
     importProductData(path, data);
 }
예제 #5
0
        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;
        }
예제 #6
0
        private void importProductData(string path, ShopifyImportData data)
        {
            try
            {
                foreach (var fileName in Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly))
                {
                    if (!ValidExtensions.Contains(Path.GetExtension(fileName).ToLower()))
                    {
                        continue;
                    }

                    var file = Path.GetFileNameWithoutExtension(fileName);
                    var splitfile = file.Split('+');

                    var title = file.Replace("_", " ").Replace("+", ", ");
                    var handle = file.ToLower().Replace("+", "-").Replace("_", "-");

                    for (var i = 0; i < data.Variants.Count; i++)
                    {
                        ShopifyProduct product;
                        if (i == 0)
                        {
                            product = new ShopifyProduct(handle, title, buildHtmlDescription(splitfile, data),
                                                             data.Vendor, data.Type, data.Tags, data.Variants[i].Item1,
                                                             data.Variants[i].Item2,
                                                             data.ImageUrl + Path.GetFileName(fileName));
                        }
                        else
                        {
                            product = new ShopifyProduct(handle, string.Empty, string.Empty,
                                 string.Empty, string.Empty, new string[] {}, data.Variants[i].Item1,
                                 data.Variants[i].Item2, string.Empty);
                        }

                        if (!_products.ContainsKey(product.Handle))
                        {
                            _products.Add(product.Handle, product);
                        }
                        else if (data.Variants.Count > 1)
                        {
                            var newHandle = handle;
                            var iterator = 1;
                            while (_products.ContainsKey(newHandle))
                            {
                                newHandle += string.Format("-variant{0}", iterator++);
                            }
                            _products.Add(newHandle, product);
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Problems importing information");
            }
        }
예제 #7
0
        private static string buildHtmlDescription(string[] filename, ShopifyImportData data)
        {
            var builder = string.Empty;

            if (data.Details.Count > 0 && data.Details[0].Contains("{{"))
            {
                foreach (var detail in data.Details)
                {
                    var line = detail.Replace("{{", string.Empty).Replace("}}", string.Empty);
                    if (!string.IsNullOrEmpty(line))
                    {
                        builder += line + '\n';
                    }
                }
            }
            else
            {
                builder += string.Format("<h4>{0}</h4>", data.DetailsHeader);
                builder += '\n';
                builder += "<ul>";
                builder += '\n';
                foreach (var detail in data.Details)
                {
                    var match = Regex.Match(detail, "{\\d+}");
                    if (match != null)
                    {
                        var num = Regex.Match(match.ToString(), "\\d+");
                        int i;
                        if (Int32.TryParse(num.ToString(), out i) && filename.Length >= i)
                        {
                            builder += string.Format("<li>{0}</li>", detail.Replace(match.ToString(), filename[i - 1].Replace("_", " ")));
                        }
                        else
                        {
                            builder += string.Format("<li>{0}</li>", detail);
                        }
                    }
                    else
                    {
                        builder += string.Format("<li>{0}</li>", detail);
                    }

                    builder += '\n';
                }
                builder += "</ul>";
            }

            builder = builder.Replace("\"", "\"\"");

            return builder;
        }
예제 #8
0
 public void ImportDataFromImages(string path, ShopifyImportData data)
 {
     importProductData(path, data);
 }