I have a Shopify store that has a couple of pages worth of products.
I followed the example on Github, but I am unable to query more than 2 pages of products.
Here's my code:
ShopifyBuy.Client().products((products, error, after) =>
{
if (error != null)
{
Debug.Log(error.Description);
switch (error.Type)
{
// An HTTP error is actually Unity's WWW.error
case ShopifyError.ErrorType.HTTP:
break;
// Although it's unlikely, an invalid GraphQL query might be sent.
// Report an issue to https://github.com/shopify/unity-buy-sdk/issues
case ShopifyError.ErrorType.GraphQL:
break;
};
}
else
{
Debug.Log("Here is the first page of products:");
// products is a List<Product>
foreach (Product product in products)
{
Debug.Log("Product Title: " + product.title());
Debug.Log("Product Description: " + product.descriptionHtml());
Debug.Log("--------");
}
}
if (after != null)
{
Debug.Log("Here is the second page of products:");
// Queries second page of products, as after is passed
ShopifyBuy.Client().products((products2, error2, after2) =>
{
foreach (Product product in products2)
{
Debug.Log("Product Title: " + product.title());
Debug.Log("Product Description: " + product.descriptionHtml());
Debug.Log("--------");
}
}, after: after);
}
else
{
Debug.Log("There was only one page of products.");
}
How can I query more pages? Or is there a way to query just a specific product?
Thanks in advance!
Have you checked if the products() method has overloaded options? If so, then you can likely drop the after argument and just iterate through the whole listing. Maybe like this...
// Retrieve products from your store
ShopifyBuy.Client().products((products, error) => {
if (error != null) {
Debug.Log("Encountered an SDK Error");
return;
// it's unlikely but if an invalid GraphQL query was sent a list of errors will be returned
}
// products is a List<Product>
Debug.Log("Your shop has " + products.Count + "products");
Debug.Log("============================");
foreach(Product product in products) {
Debug.Log("Product Title: " + product.title());
Debug.Log("Product Description: " + product.descriptionHtml());
Debug.Log("------");
}
});
User | Count |
---|---|
13 | |
12 | |
7 | |
6 | |
5 |