public void ShouldFetchARecord() { var callRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/89", EmptyQueryParametersExpectation(), null)); callRawExpectation.Returns(TaskForResult <string>("robot #89's json")); var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Robot>("robot", "robot #89's json")); var translatedRobot = new Robot { Id = 89 }; // // TODO: .Get will start setting translationExpectation.Returns(translatedRobot); var answer = Robots.Find(89); answer.Wait(); Assert.AreSame(answer.Result, translatedRobot); // check for the Parts subresource object Assert.AreEqual("/admin/robots/89/parts", answer.Result.Parts.Path()); callRawExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); }
public void ShouldFetchAListOfAllMatchedModels() { var callRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots", EmptyQueryParametersExpectation(), null)); callRawExpectation.Returns(TaskForResult <string>("json text!")); var translationExpectation = A.CallTo(() => Shopify.TranslateObject <List <Robot> >("robots", "json text!")); translationExpectation.Returns(new List <Robot>() { new Robot() { Id = 8889 } }); var answer = Robots.AsListUnpaginated(); answer.Wait(); callRawExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); Assert.AreEqual(1, answer.Result.Count); Assert.NotNull(answer.Result[0].Parts); Assert.AreEqual("/admin/robots/8889/parts", answer.Result[0].Parts.Path()); }
public static async Task <object> deleteProduct() { Shopify s = new Shopify("f53db014d644405dbea1dca767167039", "bd3ab6592ef0208b0e6edc037baaf733", "f**k-the-winter"); var res = await s.Delete("products/314329530417.json"); return(res); }
private async void ProductForm_Load(object sender, EventArgs e) { Product.SetProduct(await Shopify.GetProductAsync(FlatProduct.GetProductVariant().ProductId.Value)); bindingSource2.DataSource = Product; // this.bindingSource2.ResetBindings(false); //this.Product = await Shopify.GetProductAsync(this.FlatProduct.GetProductVariant().ProductId.Value); //this.bindingSource2.DataSource = this.Product; //this.textBoxTitle.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource2, "Title", true)); //this.textBoxVendor.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource2, "Vendor", true)); //this.textBoxDescription.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource2, "BodyHtml", true)); //this.textBoxShort.Text = this.Product.Metafields.FirstOrDefault(m => m.Key == "ShortDescription")?.Value.ToString(); //this.dataGridView1.DataSource = this.bindingSource2; //this.dataGridView1.DataMember = "Variants"; //this.dataGridView1.Columns.Remove("ImageId"); //this.dataGridView1.Columns.Remove("InventoryQuantityAdjustment"); //this.dataGridView1.Columns.Remove("OldInventoryQuantity"); //this.dataGridView1.Columns.Remove("InventoryQuantity"); //this.dataGridView1.Columns.Remove("Barcode"); //this.dataGridView1.Columns.Remove("RequiresShipping"); //this.dataGridView1.Columns.Remove("Taxable"); //this.dataGridView1.Columns.Remove("UpdatedAt"); //this.dataGridView1.Columns.Remove("CreatedAt"); //this.dataGridView1.Columns.Remove("WeightUnit"); //this.dataGridView1.Columns.Remove("CompareAtPrice"); //this.dataGridView1.Columns.Remove("Grams"); //this.dataGridView1.Columns.Remove("Position"); //this.dataGridView1.Columns.Remove("ProductId"); //this.dataGridView1.Columns.Remove("Metafields"); }
static public async Task PortCustomersAsync() { List <ShopifySharp.Customer> customers = Shopify.GetCustomers(); foreach (ShopifySharp.Customer customer in customers) { CustomersApi api = new CustomersApi(); if (customer.DefaultAddress != null) { await api.CreateCustomerAsync(new CreateCustomerRequest( GivenName : customer.FirstName, FamilyName : customer.LastName, EmailAddress : customer.Email, Address : new Address( AddressLine1 : customer.DefaultAddress.Address1, AddressLine2 : customer.DefaultAddress.Address2, Locality : customer.DefaultAddress.City, AdministrativeDistrictLevel1 : customer.DefaultAddress.ProvinceCode, PostalCode : customer.DefaultAddress.Zip, Country : "US"), PhoneNumber : customer.Phone, ReferenceId : customer.Id.Value.ToString() )); } else { await api.CreateCustomerAsync(new CreateCustomerRequest( GivenName : customer.FirstName, FamilyName : customer.LastName, EmailAddress : customer.Email, PhoneNumber : customer.Phone, ReferenceId : customer.Id.Value.ToString())); } } }
public void ShouldReplaceInstanceSubResourceForHasOnePlaceholder() { var getRobotExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/420", EmptyQueryParametersExpectation(), null)); getRobotExpectation.Returns(TaskForResult <string>("Robot #420's json")); // Robot #42 has Brain #56 var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Robot>("robot", "Robot #420's json")); var translatedRobot = new Robot { Id = 420, Brain = new HasOneDeserializationPlaceholder <Brain>(56) }; translationExpectation.Returns(translatedRobot); var answer = Robots.Find(420); answer.Wait(); getRobotExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); Assert.IsInstanceOf <SingleInstanceSubResource <Brain> >(answer.Result.Brain); Assert.AreEqual(56, answer.Result.Brain.Id); }
public void Cleanup() { List <InvSupplement> inv = GetInventory(); IEnumerable <Product> products = Shopify.GetProductsAsync().Result; foreach (Product p in products) { p.Title = p.Title.Replace("®", "").Replace("™", "").Replace("®", ""); List <InvSupplement> imported = inv.Where(i => i.Name == p.Title && p.Vendor == i.Company).ToList(); foreach (InvSupplement i in imported) { i.Imported = true; } if (imported.Count == 0) { System.Console.WriteLine($"No Matches {p.Vendor} - {p.Title}"); } } foreach (InvSupplement i in inv.Where(i2 => i2.Imported)) { int count = products.Where(p => p.Title == i.Name && p.Vendor == i.Company).Count(); if (products.Count(p => p.Title == i.Name && p.Vendor == i.Company) != 1) { System.Console.WriteLine($"No Matches {i.Company} - {i.Name}"); } } File.WriteAllText(supplement, JsonConvert.SerializeObject(inv, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); }
public async Task <IActionResult> Oauth(string code, string shop) { string qs = Request.QueryString.ToString(); if (AuthorizationService.IsAuthenticRequest(qs, _config["Keys:SecretKey"])) { string accessToken = await AuthorizationService.Authorize(code, shop, _config["Keys:ApiKey"], _config["Keys:SecretKey"]); Shopify shops = new Shopify(); shops.StoreName = shop; shops.Token = accessToken; _context.Add(shops); await _context.SaveChangesAsync(); await createTemplateAsync(shops.StoreName, shops.Token); string a = shop; return(RedirectToAction("Index", "Home", new { shop = a, })); } return(View()); }
static public async Task PortCatagories() { List <ShopifySharp.CustomCollection> list = await Shopify.GetCollections(); List <CatalogObjectBatch> batches = new List <CatalogObjectBatch>(); CatalogObjectBatch batch = new CatalogObjectBatch { Objects = new List <CatalogObject>() }; batches.Add(batch); foreach (ShopifySharp.CustomCollection collection in list) { CatalogObject category = new CatalogObject( Type: "CATEGORY", Id: $"#{collection.Title}", PresentAtAllLocations: true, CategoryData: new CatalogCategory { Name = collection.Title } ); batch.Objects.Add(category); } CatalogApi api = new CatalogApi(); BatchUpsertCatalogObjectsRequest body = new BatchUpsertCatalogObjectsRequest(Guid.NewGuid().ToString(), batches); BatchUpsertCatalogObjectsResponse response = await api.BatchUpsertCatalogObjectsAsync(body); }
public static async Task <object> getShop() { Shopify s = new Shopify("f53db014d644405dbea1dca767167039", "bd3ab6592ef0208b0e6edc037baaf733", "f**k-the-winter"); var res = await s.Get("shop.json").ConfigureAwait(true); return(res); }
public void ShouldCallActionsByProperty() { Robots.CallAction(Calculon, () => Calculon.Explode); A.CallTo(() => Shopify.CallRaw(HttpMethod.Post, JsonFormatExpectation(), "/admin/robots/42/explode", EmptyQueryParametersExpectation(), null)).MustHaveHappened(); }
public async Task <ActionResult> GetImages(long id) { var productImages = await Shopify.GetShopifyProductImages(appConfig, id); // only return the first image's source attribute // https://github.com/nozzlegear/ShopifySharp/blob/master/ShopifySharp/Entities/ProductImage.cs return(Content(productImages.FirstOrDefault().Src)); }
static public async Task PortItemsAsync(string locationId) { V1Fee tax = await CreateTaxV1(locationId); string discoutId = await CreateDiscount(locationId); List <ShopifySharp.Product> products = await Shopify.GetProductsAsync(); V1ItemsApi v1 = new V1ItemsApi(); foreach (ShopifySharp.Product prod in products) { System.Console.WriteLine(prod.Title); V1Item item = new V1Item( Name: prod.Title, Type: "NORMAL", Visibility: "PUBLIC", AvailableOnline: true, Variations: new List <V1Variation>(), Taxable: true, Fees: new List <V1Fee>() { tax } ); foreach (ShopifySharp.ProductVariant variant in prod.Variants) { V1Variation vari = new V1Variation ( Name: variant.Title, PricingType: "FIXEDPRICING", PriceMoney: new V1Money( Amount: variant.Price.HasValue ? ((int?)(variant.Price.Value * 100L)) : null, CurrencyCode: "USD" ), TrackInventory: true, UserData: variant.Id.ToString() ); item.Variations.Add(vari); } V1Item item2 = await v1.CreateItemAsync(locationId, item); ShopifySharp.ProductImage image = prod.Images.FirstOrDefault(); if (image != null) { await ImageUploader.PortImage(locationId, item2.Id, prod.Images.First().Src); } } // await SetInventory(products); await FixBarCodes(products); await FixLocations(); }
public static async Task <object> getProduct() { Shopify s = new Shopify("f53db014d644405dbea1dca767167039", "bd3ab6592ef0208b0e6edc037baaf733", "f**k-the-winter"); var arg = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("limit", "1") }; var res = await s.Get("products.json", arg).ConfigureAwait(true); return(res); }
private async void ProductsForm_Load(object sender, EventArgs e) { Products = (await Shopify.GetProducts()).ToList(); Flats = FlatProduct.FromProducts(Products).Where(fp => fp.Price == null || fp.Price.Value == 0.0m).ToList(); int count = Products.Count(p => p.Variants?.Count() == 0); BindingListProducts = new SortableBindingList <FlatProduct>(Flats); BindingSource = new BindingSource(BindingListProducts, null); dataGridView1.DataSource = BindingSource; dataGridView1.CellValueChanged += DataGridView1_CellValueChanged; dataGridView1.CellDoubleClick += DataGridView1_CellDoubleClick; }
public void BeforeEach() { Shopify = A.Fake <IShopifyAPIContext>(); A.CallTo(() => Shopify.AdminPath()).Returns("/admin"); A.CallTo(() => Shopify.GetRequestContentType()).Returns(new MediaTypeHeaderValue("application/json")); Robots = new RestResource <Robot>(Shopify); Brains = new RestResource <Brain>(Shopify); Calculon = new Robot() { Id = 42 }; CalculonsParts = new SubResource <Part>(Robots, Calculon); }
public void ShouldFetchCount() { var getRobotCountExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/count", EmptyQueryParametersExpectation(), null)); getRobotCountExpectation.Returns(TaskForResult <string>("robots count json")); var translationExpectation = A.CallTo(() => Shopify.TranslateObject <int>("count", "robots count json")); translationExpectation.Returns(34969); var answer = Robots.Count(); answer.Wait(); Assert.AreEqual(34969, answer.Result); }
public void FlatProducts() { IEnumerable <Product> prods = Shopify.GetProductsAsync().Result; File.WriteAllText(dump, JsonConvert.SerializeObject(prods, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); int count = 1; foreach (Product prod in prods) { foreach (ProductVariant pv in prod.Variants) { System.Console.WriteLine($"{count}\t{prod.Vendor}\t{prod.Title}\t{pv.Price}\t{pv.Option1}\t{pv.Option3}"); count++; } } }
private async void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { FlatProduct flat = dataGridView1.Rows[e.RowIndex].DataBoundItem as FlatProduct; ProductVariant pv = flat.GetProductVariant(); if (pv.Barcode == null) { pv.Barcode = ""; } if (pv.SKU == null) { pv.SKU = ""; } ProductVariant pv2 = await Shopify.UpdateVariant(pv); textSearch.Select(); textSearch.SelectAll(); }
public void ShouldDeleteASubResourceRecord() { var partToPost = new Part() { Id = 83 }; partToPost.SetExisting(); var deleteRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Delete, JsonFormatExpectation(), "/admin/robots/42/parts/83", null, null)); deleteRawExpectation.Returns(TaskForResult <string>("")); var answer = CalculonsParts.Delete <Part>(partToPost); answer.Wait(); deleteRawExpectation.MustHaveHappened(); }
public void ShouldFetchASubResourceRecord() { var callRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/42/parts/69", EmptyQueryParametersExpectation(), null)); callRawExpectation.Returns(TaskForResult <string>("robot #42's part #69 json")); var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Part>("part", "robot #42's part #69 json")); var translatedPart = new Part { Id = 69 }; translationExpectation.Returns(translatedPart); var answer = CalculonsParts.Find(69); answer.Wait(); Assert.AreSame(translatedPart, answer.Result); }
public void ShouldReplaceInstanceSubResourceForHasOnePlaceholdersWithinAHasOneInline() { // if we receive a has one inline, we need to be sure that the post-processing also // happens for the resourcemodels deserialized inside a HasOneInline<> var getRobotExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/420", EmptyQueryParametersExpectation(), null)); getRobotExpectation.Returns(TaskForResult <string>("Robot #420's json")); // Robot #42 has Brain #56 var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Robot>("robot", "Robot #420's json")); var translatedBrain = new Brain { Id = 747, DeepNested = new HasOneDeserializationPlaceholder <DeepNestedHasAInline>(8010) }; var translatedRobot = new Robot { Id = 420, Brain = new HasOneInline <Brain>(translatedBrain) }; translationExpectation.Returns(translatedRobot); var answer = Robots.Find(420); answer.Wait(1000); getRobotExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); Assert.IsInstanceOf <HasOneInline <Brain> >(answer.Result.Brain); var hasOneBrain = (HasOneInline <Brain>)(answer.Result.Brain); var brain = hasOneBrain.Get(); brain.Wait(1000); Assert.IsInstanceOf <SingleInstanceSubResource <DeepNestedHasAInline> >(brain.Result.DeepNested); Assert.AreEqual(8010, brain.Result.DeepNested.Id); }
public static async Task <object> putProduct() { Shopify s = new Shopify("f53db014d644405dbea1dca767167039", "bd3ab6592ef0208b0e6edc037baaf733", "f**k-the-winter"); Dictionary <string, string> param = new Dictionary <string, string> { { "title", "Really good snowboard" }, { "body_html", "<strong>Great snowboard</strong>" }, { "vendor", "Twitch" }, { "product_type", "Twitch Snowbaord" }, { "tags", "Barnes & Noble, John's Fav, Big Air" } }; Dictionary <string, Dictionary <string, string> > product = new Dictionary <string, Dictionary <string, string> > { { "product", param } }; var res = await s.Put("products/314329923633.json", JsonConvert.SerializeObject(product)).ConfigureAwait(true); return(res); }
private static void Cleanup() { IEnumerable <Customer> customers = Shopify.GetCustomers(); int count = 0; foreach (Customer c in customers) { System.Console.Write($"{++count}\r"); Address add = c.Addresses.FirstOrDefault(); if (add?.City != null) { string city = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(add.City.ToLower()); if (city != add.City) { System.Console.WriteLine($"\r{add.City} - {city}"); add.City = city; Shopify.UpdateCustomer(c); System.Threading.Thread.Sleep(500); } } // string first = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(c.FirstName); } }
public void ShouldUpdateASubResourceRecord() { var partToPost = new Part() { Id = 9777 }; var translationExpectation = A.CallTo(() => Shopify.ObjectTranslate <Part>("part", partToPost)); translationExpectation.Returns("PART 988 JSON"); var putRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Put, JsonFormatExpectation(), "/admin/robots/42/parts/9777", null, "PART 988 JSON")); putRawExpectation.Returns(TaskForResult <string>("")); var answer = CalculonsParts.Update <Part>(partToPost); answer.Wait(); translationExpectation.MustHaveHappened(); putRawExpectation.MustHaveHappened(); }
public void ShouldCreateASubResourceRecord() { var partToPost = new Part() { Sku = "0xdeadbeef" }; var translationExpectation = A.CallTo(() => Shopify.ObjectTranslate <Part>("part", partToPost)); translationExpectation.Returns("PART 988 JSON"); var postRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Post, JsonFormatExpectation(), "/admin/robots/42/parts", null, "PART 988 JSON")); postRawExpectation.Returns(TaskForResult <string>("PART 988 REAL JSON")); var resultTranslationExpectation = A.CallTo(() => Shopify.TranslateObject <Part>("part", "PART 988 REAL JSON")); // it got the id of 90 on the server var resultantPart = new Part() { Id = 90 }; resultTranslationExpectation.Returns(resultantPart); var answer = CalculonsParts.Create <Part>(partToPost); answer.Wait(); translationExpectation.MustHaveHappened(); postRawExpectation.MustHaveHappened(); resultTranslationExpectation.MustHaveHappened(); Assert.AreSame(resultantPart, answer.Result); }
public static void Main(string[] args) { // Configure OAuth2 access token for authorization: oauth2 string HMS = "sq0atp-M5ylQzjwtUqHFV_1aZBkWw"; string TEST = "sq0atp-NbIspn1KqTCzVxmJJblliQ"; Configuration.Default.AccessToken = HMS; // PortCustomersAsync().Wait(); //WebRequest.DefaultWebProxy = new WebProxy("127.0.0.1", 8888); //FixLocations().Wait(); List <ShopifySharp.Product> products = Shopify.GetProductsAsync().Result; //SetInventory(products).Wait(); //FixBarCodes(products).Wait(); ListLocationsResponse locations = GetLocations().Result; // DeleteProducts().Wait(); // PortItemsAsync(locations.Locations[0].Id).Wait(); // PortItemsAsync("me").Wait(); ListTransactionsResponse transactions = GetTransactions(locations.Locations[0].Id).Result; Customer customer = GetCustomer("Raboud", "Robert").Result; Customer customer2 = GetCustomer("Raboud", "Carrie").Result; GetProductsAsync().Wait(); //var customerTransactions = transactions.Transactions.Where(t => t.Tenders.Any(te => te.CustomerId == customer.Id)).ToList(); //foreach (var transaction in customerTransactions) //{ // foreach (var tender in transaction.Tenders) // { // if (tender.CustomerId == customer.Id) // { // tender.CustomerId = customer2.Id; // } // } //} }
public ProductsForm() { Shopify.Init(); InitializeComponent(); }
private static void PopulatePatients() { List <Patient> patients = JsonConvert.DeserializeObject <List <Patient> >(File.ReadAllText(@"C:\Users\Robert\Documents\patient.json")); List <Patient> success = new List <Patient>(); List <Patient> errors = new List <Patient>(); List <Patient> skipped = new List <Patient>(); int count = 0; List <string> emails = new List <string>(); List <string> phones = new List <string>(); IEnumerable <Customer> customers = Shopify.GetCustomers(); foreach (Customer c in customers) { if (!string.IsNullOrEmpty(c.Email)) { emails.Add(c.Email); } if (!string.IsNullOrEmpty(c.Phone)) { phones.Add(c.Phone); } } Patient patient; while ((patient = patients.FirstOrDefault()) != null) { patients.Remove(patient); File.WriteAllText(@"C:\Users\Robert\Documents\patient.json", JsonConvert.SerializeObject(patients)); // patient.EMail = isValidEmail(patient.EMail) ? patient.EMail : null; if (emails.Contains(patient.EMail)) { skipped.Add(patient); File.WriteAllText(@"C:\Users\Robert\Documents\skipped.json", JsonConvert.SerializeObject(skipped)); System.Console.WriteLine($"\rSkipping Patient {patient.PatientNo} duplicate email"); continue; } if (!string.IsNullOrEmpty(patient.EMail)) { emails.Add(patient.EMail); } else { } ShopifySharp.Address address = new Address { Address1 = patient.Address1, Address2 = patient.Address2, City = patient.City, Default = true, Zip = patient.Zip, CountryCode = "US", ProvinceCode = patient.State }; ShopifySharp.Customer customer = new ShopifySharp.Customer { Addresses = new List <Address>() { address }, Email = patient.EMail, FirstName = patient.FirstName, LastName = patient.LastName }; if (patient.CellPhone != null && IsValidUSPhoneNumber(patient.CellPhone)) { customer.Phone = patient.CellPhone; } else if (patient.HomePhone != null && IsValidUSPhoneNumber(patient.HomePhone)) { customer.Phone = patient.HomePhone; } else if (patient.WorkPhone != null && IsValidUSPhoneNumber(patient.WorkPhone)) { customer.Phone = patient.WorkPhone; } else if (patient.OtherPhone != null && IsValidUSPhoneNumber(patient.OtherPhone)) { customer.Phone = patient.OtherPhone; } if (!string.IsNullOrEmpty(customer.Phone)) { if (phones.Contains(customer.Phone)) { skipped.Add(patient); File.WriteAllText(@"C:\Users\Robert\Documents\skipped.json", JsonConvert.SerializeObject(skipped)); System.Console.WriteLine($"\rSkipping Patient {patient.PatientNo} duplicate phone"); continue; } phones.Add(customer.Phone); } try { Customer c = Shopify.CreateCustomer(customer); bool b = Shopify.CreateCustomerMetadata(c.Id.Value, "ownCustomer", "PatientNumber", patient.PatientNo); success.Add(patient); File.WriteAllText(@"C:\Users\Robert\Documents\success.json", JsonConvert.SerializeObject(success)); } catch (Exception) { errors.Add(patient); File.WriteAllText(@"C:\Users\Robert\Documents\errors.json", JsonConvert.SerializeObject(errors)); } count++; System.Console.Write($"{count}\r"); System.Threading.Thread.Sleep(1100); } }
public async Task BuildProduct(MasterProduct 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 = p.Vendor }; if (p.Sizes.Count > 0) { 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); } if (p.Flavors.Count > 0) { ProductOption po = new ProductOption { Name = "Flavor" }; foreach (string vt in p.Flavors) { po.Values = new List <string>(p.Flavors); } po.ProductId = prod.Id; (prod.Options as List <ProductOption>).Add(po); } foreach (MasterProduct.Variant v in p.Variants) { ProductVariant pv = new ProductVariant { Barcode = v.BarCode, Option1 = v.Option1, Option2 = v.Option2, Option3 = v.Option3, 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>(); // ids.Add(pv.Id.Value); // pi.VariantIds = ids; // } //} //prod = Shopify.UpdateProduct(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); } }