Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Oct 19, 2022 · 4 comments
Open

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

ghost opened this issue Oct 19, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 19, 2022

Hello everyone;

How can i listing all SKU?

@ghost
Copy link
Author

ghost commented Oct 25, 2022

solved

@mcupryk
Copy link

mcupryk commented May 21, 2023

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

@ghost
Copy link
Author

ghost commented May 22, 2023

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...

@macupryk
Copy link

Nice work. Thanks again for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants