FROM CACHE - en_header

Unity Buy SDK - NoQueryException on price (but documentation says this info should be fetched)

New Member
1 0 0

When using the Unity Buy SDK's product fetching helper function, I get a NoQueryException whenever I try to get a variant's price.

For clarity, the function I'm refering to is: ShopifyBuy.Client().products((products, error, after) => {}

This is very odd, considering the documentation for this function says it queries price and is one of the key examples on GitHub. Strangely, I can get the price of a product once adding it to a cart (but this is not ideal). Is this a bug, or am I critically misunderstanding something?



For reference, my code (Note: the merchant is initialized by "merchants[i].client = ShopifyBuy.Init(merchants[i].apiKey, merchants[i].merchantDomain)") :

public void TestShopify(Merchant merchant) //THIS SHOULD PROBABLY BE AN ENUMERATOR
//ShopifyBuy.Init(accessToken, shopDomain);

ShopifyBuy.Client().products((products, error, after) => {

Cart cart = ShopifyBuy.Client().Cart();

Debug.Log("num of products returned by Shopify: " + products.Count);
//Update ProductData for each product in Merchant's store
for (int i = 0; i < products.Count; i++)
if (merchant.productsDictionary.ContainsKey(products[i].title())) //each product fetched runs this code once
Debug.Log("shopify product:" + products[i].title());
List<ProductVariant> productVariants = (List<ProductVariant>)products[i].variants();

ProductVariant firstProductVariant = productVariants[0];
//Debug.Log(firstProductVariant.price()); //this is returning NoQueryException for price

cart.LineItems.AddOrUpdate(firstProductVariant, 1);

decimal thisProductPrice = cart.LineItems.All()[i].Price;
float thisPriceFloat = Convert.ToSingle(thisProductPrice);

for (int x = 0; x < merchant.productsDictionary[products[i].title()].Count; x++)
merchant.productsDictionary[products[i].title()][x].productData.price = thisPriceFloat;
Debug.Log("Shopify fetched product name not found in merchant productDictionary. /n Maybe there is a mismatch in product name or the products in scene have not been added to the merchant's 'products' List");






Replies 0 (0)