WDE0025: Error
WDE0025: The Stores/products collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
// For full API documentation, including code examples, vist Velo API Reference - Wix.com
$w.onReady(function () {
LoadRelatedProducts();
});
async function LoadRelatedProducts() {
let product = await $w(‘#productPage’).getProduct();
let relatedProductsResult = await Promise.all ([
relatedProductsByTable(product),
relatedProductsByPrice(product)
]);
if (relatedProductsResult[0].length > 0)
showRelatedProducts(relatedProductsResult[0]);
else
showRelatedProducts(relatedProductsResult[1]);
}
async function relatedProductsByPrice(product) {
let productId = product._Id;
let relatedByPrice = await wixData.query(`Stores/products`)
.between('price', product.price * 0.8, product.price * 1.2)
.ne('_id', productId)
.find();
return relatedByPrice.items;
}
async function relatedProductsByTable(product) {
let productId = product._id;
let relatedByTab = await Promise.all([
wixData.query('relatedProducts')
.eq('productA', productId)
.include('productB')
.find(),
wixData.query('relatedProducts')
.eq('productB', productId)
.include('productA')
.find()
]);
let relatedProducts = [
…relatedProductsByTable[0].items.map(_ => .productB),
…relatedProductsByTable[1].items.map( => _.productA)
];
return relatedProducts;
}
function showRelatedProducts(relatedProducts) {
if (relatedProducts.length > 0) {
relatedProducts.splice(4, relatedProducts.length);
$w(‘#relatedItemsRepeater’).data = relatedProducts;
$w(‘#relatedItemsRepeater’).onItemReady(relatedItemReady);
$w(‘#relatedItems’).expand();
}
else {
$w(‘#relatedItems’).collapse();
}
}
function relatedItemrReady($w, product) {
$w(‘#productimage’).src = product.mainMedia;
$w(‘#productName’).text = product.name;
$w(‘#productPrice’).text = product.formattedPrice;
$w(‘#productImage’).onClick(() =>{
wixLocation.to(product.productPageUrl);
})
}