Hi everyone,
I am looking for a way to populate a repeater with items from the Wix Store database that contains a specific collection. Here is my code :
export function button22_click(event) {
let collection = "Eggs"
refresh_repeater(collection)
}
//Refresh the repeater
function refresh_repeater(collection) {
wixData.query('Stores/Products')
.hasSome("collections", collection)
.find()
.then((results) => {
let items = results.items;
console.log(items);
$w("#repeater1").data = items;
});
}
Doing that isn’t working, since I got the following result on the console : Array(0)
However, the “Eggs” collection is existing, with this capitalization and many products have it.
Thank youuuuu for your help <3
At a glance, seems like that should work. Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.
Hi ! Thank you for your answer. I tried another method that is really more complex but seem to work (first query the ID of the specific collection in the C ollections collection, then query the products based on this ID). I hope WIX will change that in the future.
Here is the code :
import wixLocation from 'wix-location';
import wixData from 'wix-data';
$w.onReady(function () {
});
export function button22_click(event) {
refresh_repeater("Eggs")
}
//Refresh the repeater
function refresh_repeater(collection) {
$w('#button27').hide()
var ID
wixData.query('Stores/Collections')
.eq("name", collection)
.find()
.then((results) => {
let items = results.items[0];
ID = items._id;
Query(ID);
});
}
function Query(ID) {
wixData.query('Stores/Products')
.include("collections")
.hasSome("collections", ID)
.find()
.then((results) => {
let items = results.items;
console.log(items)
$w("#repeater1").data = results.items;
})
}
Fantastic solution @valentinloppe ! Thanks for sharing.