What does an uncaught products in collection error mean and how can I fix it?
Unanswered
Dwarf Crocodile posted this in #help-forum
Dwarf CrocodileOP
I have a function that gets products from a Shopify collection.
When I visit the page I get a Cannot read properties of undefined error and the page doesn't load, annoyingly it was previously working totally fine.
What does this error mean how can I fix it?
When I visit the page I get a Cannot read properties of undefined error and the page doesn't load, annoyingly it was previously working totally fine.
What does this error mean how can I fix it?
export async function getProductsInCollection() {
const query = `
{
collectionByHandle(handle: "frontpage") {
title
products(first: 60) {
edges {
node {
id
title
productType
handle
metafields(first: 2) {
edges {
node {
namespace
key
value
}
}
}
}
}
}
}`
const response = await ShopifyData(query);
const allProducts = response.data.collectionByHandle.products.edges
? response.data.collectionByHandle.products.edges
: [];
return allProducts;
}Uncaught at getProductsInCollection error
export async function filter(type) {
let filteredProducts = await getProductsInCollection();
return filteredProducts.filter((product) => product.node.productType === type);
}3 Replies
probly you are not getting the object in your json correctly . Please check what are your properties .
In example if you have
data:{user:{
name:"PiggyDev"
}
} that would be data.user.nameyou cqan always console.log the data you fetch so you can see what to do with the properties 😉