WooCommerce.NET icon indicating copy to clipboard operation
WooCommerce.NET copied to clipboard

I can't retrieve the stock code of the products.

Open ghost opened this issue 2 years ago • 4 comments

Hello everyone;

How can i listing all SKU?

ghost avatar Oct 19 '22 10:10 ghost

solved

ghost avatar Oct 25 '22 07:10 ghost

@palmeItGit please paste your solution in case some one needs it. Thanks

mcupryk avatar May 21 '23 23:05 mcupryk

Hi! you guessed it, I don't remember :) but I found a code like this: Firstly you must (get all product(s) / filtered product(s) after than

private async Task<bool> CheckExistOnWoo(string ArtikelNr)
        {
            //First step get source products data
            bool isExist = false;
            RestAPI rest = new RestAPI(webConnecs.StoreAddress, webConnecs.Key, webConnecs.Secret, jsonDeserializeFilter: trimstr);
            WCObject wc = new WCObject(rest);

            List<Product> products = new List<Product>();

            #region GetProductWithIdFromWeb
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("per_page", "100");
            dictionary.Add("sku", ArtikelNr);
            int pageNumber = 1;
            dictionary.Add("page", pageNumber.ToString());
            bool endWhile = false;
            while (!endWhile)
            {
                var productsTemp = await wc.Product.GetAll(dictionary);

                if (productsTemp.Count > 0)
                {
                    products.AddRange(productsTemp);
                    pageNumber++;
                    dictionary["page"] = pageNumber.ToString();
                }
                else
                {
                    endWhile = true;
                }
            }
            #endregion

            //Now you can check sku data...
            foreach (Product p in products)
            {
                if (p.sku == ArtikelNr)
                {
                    isExist = true;
                    break;
                }
            }

            return isExist;
        }

i hope you can found a sloution...

ghost avatar May 22 '23 07:05 ghost

Nice work. Thanks again for the update.

macupryk avatar May 23 '23 00:05 macupryk