Wix Stores "Products" Collection fields - Bug or flaw?

Is it really not possible to query or even get the collections for each product?

Using getProduct() on the product page returns “undefined” for all products (on all Wix Stores on all websites. I have tested 5.)

Collections is not listed as a member in the reference docs even though it appears in the console.

Even when attempting to query the Stores/Products collection, “undefined” is returned for all products each time.

Is there absolutely no way to pull this information at all? Why? How?

1 Like

Collections is reference field, you need to include it in your request

1 Like

But so is Inventory Item is a reference field and it doesn’t return undefined.

For example, if check the Wix Blog app. To get the categories for the current post (The categories is also a multi reference field) I do not get “undefined”. It returns the actually array of categories in that field.

But when I do this for Wix Stores, to get what categories (or “collections”) array the current product has in that field, it always returns “undefined”. As if the field was blank. Which it’s not. So how do I return the categories the product belongs to?

@code-queen The different from the inventory is that it’s a single reference field.

What you got I the id of the referenced item (inventory) not the inventory itself

But I agree with you It should work as the “getPost()” API

You definitely can pull it. I haven’t used getProduct(), but querying the Stores/Products ( with its custom limit on 100 items) database directly does give both the products and the collection IDs, which you can cross reference against the Stores/Collections Database. I’m guessing you tried that already?

Yup!

Actually Quentin jumped in video call with me to brainstorm.

Results …

Cannot get collections info via getProduct().
Cannot get collections info via dataset filter.
Cannot get collections info via dataset connections.
CAN get collections info via query ONLY.

Aye. Well that’s a big learning for today. Did it help with the issue you were having with the code?

Hi
I’m Oded from Wix.

So right now, there 2 ways you can do this

You can use query + include - if you need this for multiple products
wixData.query( “Stores/Products” ).include( “collections” ).find().then(x => {
console.log(x.items[ 0 ].collections);
});

You can query referenced - if you need this for a single product
wixData.queryReferenced( “Stores/Products” , “f2c944b4-9766-913c-e0e2-41a6e0136989” , “collections” ).then(x => {
console.log(x.items);
});

$w(“#productPage).getProduct does not support returning the collections at all as you saw in the documentation. I agree that the fact that we return undefined (both here and when include is missing) is confusing.
I can also imagine another parameter sent to $w(”#productPage).getProduct which will allow you to ask for collections, but I wouldn’t say it has a huge value since you can use query referenced.

Thanks for your feedback!

@chris-derrell For sure. Sad that they did not include it in the getProducts() API for Wix Stores but they did include for the getPost() API in Wix Blog. Inconsistencies like that make it more challenging to remember which app does or does not ‘have this or that’.

It would be of great value to keep the API’s consistent. We are able to pull such information from the Wix Blog API (getPost) but not from Wix Stores API (getProduct).

Every other field for that product can be retrieved by using getProduct().

Now we have to build an entirely separate query just to retrieve the 1 last field from the Stores/Products collection because getProduct won’t let us view that single field value. It is not very efficient.

@code-queen
While I understand the need for consistency, I will explain the reasoning behind this.

A product, can be part of many collections. Could 3, 10, maybe 1000 or more.
Such use cases, require another API to allow pagination over the referenced item, in this case collections.

So while I understand that making another API call adds complexity, I’m afraid that it’s a must in this case

Please let me know if that makes sense to you

Note that I did not address the question of why blog API works the way it does, simply because I do not know the specifics of that product

If anyone has trouble running this code: you need to correct the double quotes to " instead of ” (look closely, they are different)