static public CustomCollection CreateCustomCollection(string collection) { CustomCollectionService service = CustomCollectionService; collection = collection.Trim(); IEnumerable <CustomCollection> customs = service.ListAsync().Result; CustomCollection cc = customs.FirstOrDefault(c => c.Title == collection && c.PublishedScope != "global"); if (cc != null) { // service.DeleteAsync(cc.Id.Value).Wait(); } // customs = service.ListAsync().Result; if (customs.All(c => c.Title != collection)) { string handle = collection.Replace(" ", "").Replace('&', '-'); cc = new CustomCollection() { Title = collection, Handle = handle, PublishedScope = "global", BodyHtml = "", Published = true, PublishedAt = DateTime.UtcNow, SortOrder = "alpha-asc" }; cc = service.CreateAsync(cc).Result; } return(cc); }
public async Task InitializeAsync() { var policy = new SmartRetryExecutionPolicy(); Service.SetExecutionPolicy(policy); CustomCollectionService.SetExecutionPolicy(policy); ProductService.SetExecutionPolicy(policy); // Create a custom collection to use with these tests. var collection = await CustomCollectionService.CreateAsync(new CustomCollection() { Title = "Things", Published = false, BodyHtml = "<h1>Hello from ShopifySharp</h1>", Image = new CustomCollectionImage() { Src = "http://placehold.it/250x250" } }); CollectionId = collection.Id.Value; // Create a collection to use with get, list, count, etc. tests. await Create(); }
public async Task InitializeAsync() { var policy = new LeakyBucketExecutionPolicy(); Service.SetExecutionPolicy(policy); CollectService.SetExecutionPolicy(policy); ProductService.SetExecutionPolicy(policy); CustomCollectionService.SetExecutionPolicy(policy); // Create a custom collection to use with these tests. var collection = await CustomCollectionService.CreateAsync(new CustomCollection() { Title = "Things", Published = false, BodyHtml = "<h1>Hello from ShopifySharp</h1>", Image = new CustomCollectionImage() { Attachment = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" } }); CollectionId = collection.Id.Value; // Create a collection to use with get, list, count, etc. tests. await Create(); }
public async Task DisposeAsync() { foreach (var obj in Created) { try { await CollectService.DeleteAsync(obj.Id.Value); await ProductService.DeleteAsync(obj.ProductId.Value); } catch (ShopifyException ex) { if (ex.HttpStatusCode != HttpStatusCode.NotFound) { Console.WriteLine($"Failed to delete created Collect with id {obj.Id.Value}. {ex.Message}"); } } } // Delete the collection if (CollectionId != 0) { await CustomCollectionService.DeleteAsync(CollectionId); } }
private async Task <CustomCollection> AddColletion(string title) { var service = new CustomCollectionService(shopifyUrl, shopifyTokenAcces); return(await service.CreateAsync(new CustomCollection() { Title = title, Published = true, PublishedAt = DateTime.UtcNow })); }
private async Task GetCollection(string collectionName) { var service = new CustomCollectionService(shopifyUrl, shopifyTokenAcces); var collections = await service.ListAsync(); var collection = collections.Where(c => c.Title == collectionName).FirstOrDefault(); if (collection == null) { collection = await AddColletion(collectionName); } }
static async public Task <List <CustomCollection> > GetCollections() { List <CustomCollection> list = new List <CustomCollection>(); int count = await CustomCollectionService.CountAsync().ConfigureAwait(false); int pages = (count / 250) + 1; for (int page = 1; page <= pages; page++) { CustomCollectionFilter filter = new CustomCollectionFilter { Limit = 250, Page = page }; list.AddRange(await CustomCollectionService.ListAsync(filter)); } return(list); }
static public Collect AddProductToCollection(Product p, string collection) { Collect retVal = null; if (p.Id.HasValue) { collection = collection.Trim(); IEnumerable <CustomCollection> customs = CustomCollectionService.ListAsync().Result; CustomCollection cc = customs.FirstOrDefault(c => c.Title == collection); if (cc == null) { cc = CreateCustomCollection(collection); } Collect collect = new Collect() { ProductId = p.Id.Value, CollectionId = cc.Id.Value }; retVal = CollectService.CreateAsync(collect).Result; } return(retVal); }
public async Task InitializeAsync() { var policy = new LeakyBucketExecutionPolicy(); Service.SetExecutionPolicy(policy); CustomCollectionService.SetExecutionPolicy(policy); ProductService.SetExecutionPolicy(policy); // Create a collection to use with these tests. var collection = await CustomCollectionService.CreateAsync(new CustomCollection() { Title = "Things", Published = false, Image = new CustomCollectionImage() { Src = "http://placehold.it/250x250" } }); CollectionId = collection.Id.Value; // Create a collection to use with get, list, count, etc. tests. await Create(); }