Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }