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

Product.Variations count is zero for ~90% of products with WooCommerce 6.6.1 update

Open JayMoorhouse opened this issue 2 years ago • 2 comments

Make sure you have included the below details when open an issue. Thank you.

Wordpress version, WooCommerce version and WooCommerce.NET version

  • We updated Wordpress core 5.9.2 -> 6.0 and WooCommerce 6.3.1->6.6.1

Steps to replicate the issue The below method is used to get a list of published products:

public async Task<List<Product>> GetPublishedProducts()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("per_page", "100");
            int pageNumber = 1;
            dic.Add("page", pageNumber.ToString());
            dic.Add("status", "publish");
            List<Product> products = new List<Product>();
            bool endWhile = false;
            while (!endWhile)
            {
                var productsTemp = await _WCObject.Product.GetAll(dic);
                if (productsTemp.Count > 0)
                {
                    products.AddRange(productsTemp);
                    pageNumber++;
                    dic["page"] = pageNumber.ToString();
                }
                else
                {
                    endWhile = true;
                }
            }
            return products;
        }

Then, iterating the products, I check for variations so I can grab them too:

foreach (var product in products)

            {

                if (product.variations != null && product.variations.Count > 0)

                { ...

As of our WooCommerce update (above), the total amount of variable products pulled from our production environment went down from 577 to 29. The simple products are unchanged. The above check is showing product.variations.Count is zero for products that definitely have variations in WooCommerce.

Details of the error message if there is any N/A

Any insight would be appreciated. I don't know why 49 are still working; at face value they don't have any differences with the ones that aren't.

EDIT I'm using v0.8.2. I just updated to v0.8.4 and I'm testing--will follow up ASAP

JayMoorhouse avatar Jul 05 '22 14:07 JayMoorhouse

Update: v0.8.4 has the same issue. I will revert WooCommerce version, but I'd still like to properly understand this issue.

JayMoorhouse avatar Jul 05 '22 14:07 JayMoorhouse

Update: _WCObject.Product.Variations.GetAll still works and returns variations on a product that has variations. Just odd that the Product.Variations.Count is 0. Now I have to run it on every product instead of only the ones that has variation.count > 0 which is fine, but obviously a lot worse for performance.

JayMoorhouse avatar Jul 05 '22 15:07 JayMoorhouse