public void Supplement() { List <InvSupplement> inv = null; if (File.Exists(supplement)) { inv = JsonConvert.DeserializeObject <List <InvSupplement> >(File.ReadAllText(supplement)); } else { CleanupInventory(master, cleaned); inv = JsonConvert.DeserializeObject <List <InvSupplement> >(File.ReadAllText(cleaned)).Where(i => i.Company == "RLC Labs").ToList(); } List <RLCProduct> prods = GetProducts(); foreach (InvSupplement i in inv) { i.productNumber = ""; if (i.Active) { i.Name = i.Supplement.Substring(0, i.Supplement.LastIndexOf(" - ")); // if (string.IsNullOrEmpty(i.Size)) { if (i.Supplement.Contains("#1000")) { i.Size = "1000 CT"; } else if (i.Supplement.Contains("#120")) { i.Size = "120 CT"; } else if (i.Supplement.Contains("#100")) { i.Size = "100 CT"; } else if (i.Supplement.Contains("#90")) { i.Size = "90 CT"; } else if (i.Supplement.Contains("#60")) { i.Size = "60 CT"; } else if (i.Supplement.Contains("#30")) { i.Size = "30 CT"; } } if (i.Size != null) { if (i.Active) { RLCProduct prod = prods.FirstOrDefault(p => p.Name == i.Name); if (prod == null) { prod = new RLCProduct { Name = i.Name }; prods.Add(prod); } // else { RLCProduct.Variant v; if (!prod.Sizes.Contains(i.Size)) { prod.Sizes.Add(i.Size); v = new RLCProduct.Variant { ImageUrl = i.ImageUrl, Option1 = i.Size, Price = i.Retail }; v.SKU = Path.GetFileNameWithoutExtension(v.ImageUrl); v.ImageUrl = i.ImageUrl; prod.Variants.Add(v); } } } } else { System.Console.WriteLine($"No Size OrthoProduct Product - {i.Name}"); } } } File.WriteAllText(CacheFile, JsonConvert.SerializeObject(prods, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); File.WriteAllText(supplement, JsonConvert.SerializeObject(inv, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); }
private async Task BuildProduct(RLCProduct p) { Product prod = new Product { Options = new List <ProductOption>(), Variants = new List <ProductVariant>(), Images = new List <ProductImage>(), PublishedScope = "global", Title = p.Name, BodyHtml = p.Description, Vendor = "RLC Labs" }; ProductOption po = new ProductOption { Name = "Size" }; foreach (string vt in p.Sizes) { po.Values = new List <string>(p.Sizes); } po.ProductId = prod.Id; (prod.Options as List <ProductOption>).Add(po); foreach (RLCProduct.Variant v in p.Variants) { ProductVariant pv = new ProductVariant { Barcode = v.BarCode, Option1 = v.Option1, Option2 = v.Option2, Option3 = v.Option3, SKU = "RLC-" + v.ImageUrl, Taxable = true, InventoryManagement = "shopify", InventoryQuantity = 0, Price = v.Price }; (prod.Variants as List <ProductVariant>).Add(pv); if (!string.IsNullOrEmpty(v.ImageUrl)) { ProductImage image = new ProductImage(); string pngFile = $"f:\\temp\\Images\\RLC Labs\\{v.ImageUrl}.png"; image.Attachment = Convert.ToBase64String(File.ReadAllBytes(pngFile)); image.Filename = $"{pv.SKU}.png"; (prod.Images as List <ProductImage>).Add(image); } } prod = await Shopify.CreateProductAsync(prod); foreach (ProductVariant pv in prod.Variants) { ProductImage pi = prod.Images.FirstOrDefault(pii => pii.Src.Contains($"/{pv.SKU}.png")); if (pi != null) { List <long> ids = new List <long> { pv.Id.Value }; pi.VariantIds = ids; } } prod = await Shopify.UpdateProductAsync(prod); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "ShortDescription", p.BriefDescription); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "Benefits", p.Benefits); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "Contains", p.Contains); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "Directions", p.Directions); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "DoesNotContain", p.DoesNotContain); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "Ingredients", p.Ingredients); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "PatentInfo", p.PatentInfo); Shopify.CreateProductMetadata(prod.Id.Value, "ownProduct", "Storage", p.Storage); foreach (string collect in p.Categories) { Shopify.AddProductToCollection(prod, collect); } }