Exemplo n.º 1
0
        public Task <Dictionary <string, int> > UpdateSkusQuantityAsync(Dictionary <string, int> skusQuantities)
        {
            return(base.SendRequestAsync <Dictionary <string, int> >(this._serviceUrl, (url, mark) =>
            {
                if (base.apiVersion == WooCommerceApiVersion.Legacy)
                {
                    WooCommerceLogger.LogTrace("Updating variation quantities in legacy is not supported");
                }

                return base.WCObject.UpdateSkusQuantityAsync(skusQuantities, base.Config.ProductsPageSize, url, mark);
            }));
        }
Exemplo n.º 2
0
        public async Task <Dictionary <string, int> > UpdateSkusQuantityAsync(Dictionary <string, int> skusQuantities, int pageSize, string url, Mark mark)
        {
            var productsToUpdate   = new List <QuantityUpdate>();
            var variationsToUpdate = new Dictionary <ProductId, IEnumerable <QuantityUpdate> >();

            await GetProductsAndVariationsToUpdateAsync(async filter => await GetNextProductPageAsync(filter),
                                                        async productId => await CollectVariationsByProductFromAllPagesAsync(productId, pageSize),
                                                        skusQuantities, pageSize, productsToUpdate, variationsToUpdate);

            var variationsJson = variationsToUpdate.Select(x => new { ProductId = x.Key.Id, Variations = x.Value }).ToJson();

            WooCommerceLogger.LogTrace(Misc.CreateMethodCallInfo(url, mark, payload: string.Format("productsToUpdate: {0}. variationsToUpdate: {1}", productsToUpdate.ToJson(), variationsJson)));
            var updatedProducts = await UpdateProductsAsync(productsToUpdate);

            var updatedVariations = (await UpdateVariationsAsync(variationsToUpdate)).ToDictionary(p => p.Sku, p => p.Quantity ?? 0);

            return(updatedProducts.Concat(updatedVariations).ToDictionary(p => p.Key, p => p.Value));
        }