Hello, I have spent a lot of time looking trough doc and other forum questions but with no luck.
Database has collections Stores/Products and Stores/Collections
My questions…
- Are Products and Collections Referenced (do they have ReferenceField),from DB schema I assume they are not ?
- Is there a way to query data as simple as this (In product page show product collections)
For example,
wixData.query(‘Stores/Products’).include(“collections”)
.find().then((r) => { console.log(r); })
- Products and Collections Hooks doesn’t work !! But you can add them(Very confused) or they do work?
I found this, but it works only one way.
This code is from Velo: Wix Stores "Products" Collection Fields | Help Center | Wix.com
// query the “Stores/Products” collection by collection ID
import wixData from ‘wix-data’;
wixData.query(‘Stores/Products’).hasSome(‘collections.id’, [‘collectionID’, …]).find() .then(console.log)
My requirments the other way.
(‘Stores/Collections’).hasSome('products.id,[‘productID’,…].find()
This trows error:
Error: {“message”:“Unknown token products.id → Map($hasSome → List(b803a783-04bb-645a-607f-b058914f0765))”}
I posted on the wrong forum section, and you cannot change that 
Hi @raimondssiro ,
I also have this kind of questions, did you find anything interesting about that?
Like for example, how to get all collections from a product id, or get the collections without querying the db constantly?
My objective is to get all wix stores collections from a list of products, but I found that’s not possible to access to the ‘collections.id’ field ( here ) from the product item in Stores/Products. You can only use the ‘collections.id’ together with wix-data for queries or filters.
Therefore, you need to always perform one separate query to the database in order to see whether there exists that product with a previously known collection id.
It would really help to have access (just read-only as all the other fields) to the ‘collections.id’ field from the product item itself.
Anyone that could help on this? Or tell if it will be possible in a short term to have access to the ‘collections.id’ field in Corvid?
Thanks!
#corvid #wixcode #wixstores #stores #products #collections #database #query #field #filter
Yes and me too. I need to be able to see a particular product as to what collections it belongs to. This is inside the store/products collection, but I do not get that piece of the object when I query stores/products?
Moving this to discussions.
Hi @ Gaspar Melsión.
Do you find a solution yet? I got the same problem.
I think a found something close to what you are looking for, https://www.wix.com/velo/forum/community-discussion/wix-stores-products-collection-fields-bug-or-flaw
the code looks like this:
wixData.query( “Stores/Products” ).include( “collections” ).find().then(x => { console.log(x.items[ 0 ].collections); });
OR
wixData.queryReferenced(“Stores/Products”, “f2c944b4-9766-913c-e0e2-41a6e0136989”, “collections”).then(x => {
console.log(x.items);
});