We've built a headless ecommerce site for our client. In Prismic, there are three custom types related to this problem: Categories, Product Types and Products.
Product Types like "Cleanser" or "Serum" belong to a Category called "Skincare". Others like "Shampoo" or "Conditioner" belong to a Category called "Body/Wellness"
In effect:
- Products belong to Product Types.
- Product Types belong to Categories
- Categories have many Products through Product Types.
We have Product Landing Pages for both Product Types and Categories, each showing products related to that Type.
The problem in question is that specific products are missing when I view the category landing page, but not when I view the Product Type Landing page.
The products show up when viewing the Product Type Landing Page, but they do not show up when viewing the Shop Category landing page.
I've verified that there isn't any front-end code that's filtering out the products in question. They're simply not present in our Prismic GraphQL response.
The code to get the Product Type LP products works like this:
const fetchProductTypeProducts = gql`
query($cursor: String!, $uid: String!, $numResults: Int!) {
allProducts(
after: $cursor
first: $numResults
where: { product_type: $uid }
) {
title
//
}`
// then in another file, we use the query like so.
// this works as expected.
const { data } = await prismicClient.query({
query: fetchProductTypeProducts,
variables: {uid: uid, cursor: cursor}
})
The code for the Categories Landing Pages works a little differently. Each Category has X number of Product Types. So we map over an array of Product Types in the Category and run the query above, like so:
const productData = await Promise.all(
productTypes.map(async prodType => {
return (
await prismicClient.query({
query: fetchProductTypeProducts,
variables: { uid: prodType.id, cursor: cursor },
})
).data
})
)
So in effect, the same query is being run both the Product Type Landing Page and the Shop Category Landing Page. But on the Shop Category Landing Page, a few, specific products are not being returned from Prismic.
My repository name is gee-beauty. I can also provide you with the specific document IDs that are missing from the Shop Category Landing Page, if that would help!
Thank you!