public async Task <List <Product> > GetAllProducts(ProductDetailModel model) { Product product = new Product(); List <Product> Products = new List <Product>(); string msg; try { var allProducts = new List <Product>(); var service = new ProductService(model.shopifyurl, model.token); var page = await service.ListAsync(new ProductListFilter { Limit = 250, }); //allProducts.AddRange(page.Items); while (true) { allProducts.AddRange(page.Items); if (!page.HasNextPage) { break; } page = await service.ListAsync(page.GetNextPageFilter()); } Products = allProducts; var mservice = new MetaFieldService(model.shopifyurl, model.token); foreach (var item in Products) { var metafields = await mservice.ListAsync(Convert.ToInt64(item.Id), "products"); string value = JsonConvert.SerializeObject(metafields.Items); item.Metafields = metafields.Items; foreach (var vgt in item.Variants) { var vmetafields = await mservice.ListAsync(Convert.ToInt64(vgt.Id), "variants"); vgt.Metafields = vmetafields.Items; } } } catch (Exception ex) { msg = ex.Message.ToString(); } return(Products); }
public async Task <Product> GetProduct(ProductDetailModel model) { Product product = new Product(); string msg; try { var allProducts = new List <Product>(); var service = new ProductService(model.shopifyurl, model.token); product = await service.GetAsync(Convert.ToInt64(model.productId)); var mservice = new MetaFieldService(model.shopifyurl, model.token); foreach (var vgt in product.Variants) { var vmetafields = await mservice.ListAsync(Convert.ToInt64(vgt.Id), "variants"); vgt.Metafields = vmetafields.Items; } } catch (Exception ex) { msg = ex.Message.ToString(); } return(product); }
public async Task <string> AddMetaFeilds(List <Product> products, string shopifyurl, string token) { foreach (var item in products) { long id = Convert.ToInt64(item.Id); var service = new MetaFieldService(shopifyurl, token); var count = await service.CountAsync(id, "products"); var metafields = await service.ListAsync(id, "products"); foreach (var item1 in metafields.Items) { await service.DeleteAsync(Convert.ToInt64(item1.Id)); } var metafield1 = new MetaField() { Namespace = "products/update", Key = "myKey", Value = "5", ValueType = "integer", Description = "This is a test meta field. It is an integer value.", OwnerResource = "products/update", }; //Create a new metafield on a product metafield1 = await service.CreateAsync(metafield1, id, "products"); } return(""); }
static async public Task <List <Product> > GetProducts(bool withMetafields = false) { List <Product> products = new List <Product>(); try { int count = await ProductService.CountAsync(); int pages = (count / 250) + 1; for (int page = 1; page <= pages; page++) { ProductFilter filter = new ProductFilter { Limit = 250, Page = page }; products.AddRange(await ProductService.ListAsync(filter)); } if (withMetafields) { foreach (Product prod in products) { prod.Metafields = await MetaFieldService.ListAsync(prod.Id.Value, "products"); } } } catch (Exception e) { } return(products); }
public async Task <IReadOnlyCollection <MetaField> > ListUpdatedSinceAsync(DateTimeOffset sinceDate) { var filter = new MetaFieldFilter() { Order = "updated_at asc", Limit = 200, UpdatedAtMin = sinceDate.Subtract(TimeSpan.FromSeconds(1)) }; var metaFields = await _metaFieldService.ListAsync(filter); return(metaFields.ToArray()); }
internal static async Task <Product> GetProductAsync(long value) { Product product = null; try { product = await ProductService.GetAsync(value); product.Metafields = await MetaFieldService.ListAsync(value, "products"); foreach (ProductVariant pv in product.Variants) { pv.Metafields = await MetaFieldService.ListAsync(pv.Id.Value, "variants"); } } catch (Exception e) { } return(product); }
static public bool CreateMetadata(string type, long id, string ns, string key, object value, string description = null) { if (value == null) { return(false); } string valueType; if (value is int) { valueType = "integer"; } else if (value is string) { valueType = "string"; if (string.IsNullOrEmpty(value as string)) { return(false); } } else { return(false); } MetaField meta = new MetaField() { Namespace = ns, Key = key, Value = value, ValueType = valueType }; MetaField t = MetaFieldService.CreateAsync(meta, id, type).Result; IEnumerable <MetaField> metas = MetaFieldService.ListAsync(id, type).Result; return(true); }