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

Product Variant Metafields #1024

Open
waynevanrooyen1971 opened this issue Feb 21, 2024 · 3 comments
Open

Product Variant Metafields #1024

waynevanrooyen1971 opened this issue Feb 21, 2024 · 3 comments
Labels

Comments

@waynevanrooyen1971
Copy link

I am trying to get the variant metafields using below code and even though i know a product hass metafields all the products are returning metafields ass null. Please explain what i am doing wrong.

var filter = new ProductListFilter
{
Limit = pageSize,
SinceId = sinceId
};

            // Get products from the Shopify store
            var productList = await service.ListAsync(filter);

            // Check if there are more products to retrieve
            if (productList.Items.Count() < pageSize)
            {
                hasNextPage = false;
            }
            else
            {
                // Set the sinceId for the next page
                sinceId = productList.Items.Last().Id;
            }

            System.Diagnostics.Debug.WriteLine($" Page Size:" + pageSize + " Has Page:" + hasNextPage);

            foreach (var product in productList.Items)
            {
                if(product.Title.Contains("Finley Stripe See Through"))
                {
                    Debug.WriteLine(product.Title);
                }
                var variantservice = new ProductVariantService(shopDomain, accessToken);
                var variantfilter = new ProductVariantListFilter
                {
                    Limit = 30
                    
                };
                var variants = await variantservice.ListAsync(product.Id ?? 0, variantfilter);
                foreach (var variant in variants.Items)
                {
                    Debug.WriteLine(product.Title + "--" + variant.Title);         
                    Debug.WriteLine(variant.Metafields);
                }
                }
@waynevanrooyen1971
Copy link
Author

var service = new MetaFieldService(myShopifyUrl, shopAccessToken);
var metafields = await service.ListAsync(productId, "products");

Seems like "products" should me a listfilter, even though changed to one still not getting any

@waynevanrooyen1971
Copy link
Author

My BAD wass doin it all wrong

@waynevanrooyen1971
Copy link
Author

OK bit of an issue here with variant metafields if the metafield does not have some sort of existing value there is no way of you getting and id as far as i can see so i want to write size chart info into a metafield like so

var mpnmetafield = await metafieldservice.UpdateAsync(metafield.Id ?? 0, new MetaField()
{
Value = xxxxxxl
});

cant do it as metafield.Id does not exist until there is already an actual value. I had to update all the metafield manually via UI then ran same code and it worked. Found same issue on the community for shopify.
Just a heads up if anyone hass the same issue

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

No branches or pull requests

2 participants