Hey
I have no idea if my brain just stopped working or if I am this bad but I can't make the below work in the order I need to get it executed.
I have a forEach loop and inside this forEach I need to get another functions returning value to use it but it don't wait for the value as it should.
function getAssortmentTitleFromProductId(prodId) {
return wixData.query("ProductCategoryItems")
.eq("product", prodId)
.limit(1)
.find()
.then((proCat) => {
if (proCat.totalCount > 0) {
return proCat.items[0].title;
}
return "";
});
}
The above function will get the products category name and return it. This is tested and it works as it should.
The below is the forEach and it will console log the product data first for all and then the console logging for the awaited function will be logged.
results.items.forEach(async(product) => {
let assortmentTitle = await getAssortmentTitleFromProductId(product._id);
console.log( assortmentTitle) ;
console.log(product);
});
Please help this f____d up brain back to work.