Пример #1
0
        private static void OptionsListing(GOshopAPISoapClient service)
        {
            int pageSize    = 5;
            int currentPage = 1;
            int fetchedProducts;
            var definitions = service.FeaturesAndDictionariesList();

            do
            {
                var options = service.OptionsList(new OptionQuery
                {
                    Page     = currentPage,
                    PageSize = pageSize,
                    IncludeOptionDictionaries = true
                });
                fetchedProducts = options.Length;

                foreach (var option in options)
                {
                    Console.WriteLine($"Option Listing: {option.OptionId}");

                    if (option.Dictionaries != null)
                    {
                        foreach (var dictionary in option.Dictionaries)
                        {
                            Console.WriteLine($"Dictionary value: {dictionary.DictionaryValue}, feature is: {definitions.Single(x => x.FeatureId == dictionary.FeatureId).FeatureName}");
                        }
                    }
                }

                currentPage++;
            } while (fetchedProducts >= pageSize);
        }
Пример #2
0
        private static void StockAndPriceUpdating(GOshopAPISoapClient service)
        {
            int pageSize    = 100;
            int currentPage = 1;
            int fetchedProducts;
            var allItems = new List <ProductOption>();

            do
            {
                var options = service.OptionsList(new OptionQuery
                {
                    Page     = currentPage,
                    PageSize = pageSize
                });

                fetchedProducts = options.Length;
                allItems.AddRange(options);
                currentPage++;
            } while (fetchedProducts >= pageSize);


            var testUpdateById  = allItems.Where(x => x.OptionId % 3 == 0).Select(x => x.OptionId);
            var testUpdateByEAN = allItems.Where(x => x.OptionId % 3 == 1).Select(x => x.EAN);
            var testUpdateBySKU = allItems.Where(x => x.OptionId % 3 == 2).Select(x => x.SKU);

            var request = new List <OptionUpdateRequest>();


            var random = new Random();

            foreach (var i in testUpdateById)
            {
                request.Add(new OptionUpdateRequest
                {
                    UpdateById        = i,
                    CatalogPriceGross = random.NextDecimal(100, 200),
                    Stock             = random.Next(0, 200),
                    PriceGross        = random.NextDecimal(100, 200)
                });
            }

            foreach (var i in testUpdateByEAN)
            {
                request.Add(new OptionUpdateRequest
                {
                    UpdateByEAN       = i,
                    CatalogPriceGross = random.NextDecimal(100, 200),
                    Stock             = random.Next(0, 200),
                    PriceGross        = random.NextDecimal(100, 200)
                });
            }

            foreach (var i in testUpdateBySKU)
            {
                request.Add(new OptionUpdateRequest
                {
                    UpdateBySKU       = i,
                    CatalogPriceGross = random.NextDecimal(100, 200),
                    Stock             = random.Next(0, 200),
                    PriceGross        = random.NextDecimal(100, 200)
                });
            }

            var batchSize    = 50;
            var rowsAffected = 0;

            Console.WriteLine($"Large update started, parts by {batchSize} in batch");

            for (var i = 0; i < request.Count; i += batchSize)
            {
                var items  = request.Skip(i).Take(batchSize);
                var result = service.OptionsStockAndPriceUpdate(items.ToArray());
                Console.WriteLine($"Batch part done, items processed: {i}, succes: {result.Count(x => x.ItemWasFound)}");
            }


            Console.WriteLine($"Large update ended, rows affected {rowsAffected}");
        }