From 8ff670d7d61778a9792e3ff9d52e81312e529a90 Mon Sep 17 00:00:00 2001 From: Michael Novotny Date: Fri, 21 Apr 2023 11:19:08 -0500 Subject: [PATCH] Fixes quirks with featured and related products. (#978) --- app/product/[handle]/page.tsx | 2 +- components/grid/three-items.tsx | 2 +- lib/shopify/queries/collection.ts | 4 ++-- lib/shopify/types.ts | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/product/[handle]/page.tsx b/app/product/[handle]/page.tsx index 5959a00c1..612cd0236 100644 --- a/app/product/[handle]/page.tsx +++ b/app/product/[handle]/page.tsx @@ -99,7 +99,7 @@ export default async function ProductPage({ params }: { params: { handle: string async function RelatedProducts({ id }: { id: string }) { const relatedProducts = await getProductRecommendations(id); - if (!relatedProducts) return null; + if (!relatedProducts.length) return null; return (
diff --git a/components/grid/three-items.tsx b/components/grid/three-items.tsx index eeec2ce50..6814a171a 100644 --- a/components/grid/three-items.tsx +++ b/components/grid/three-items.tsx @@ -37,7 +37,7 @@ function ThreeItemGridItem({ export async function ThreeItemGrid() { // Collections that start with `hidden-*` are hidden from the search page. - const homepageItems = await getCollectionProducts('hidden-homepage-featured-items', 3); + const homepageItems = await getCollectionProducts('hidden-homepage-featured-items'); if (!homepageItems[0] || !homepageItems[1] || !homepageItems[2]) return null; diff --git a/lib/shopify/queries/collection.ts b/lib/shopify/queries/collection.ts index 8df815992..423cb3217 100644 --- a/lib/shopify/queries/collection.ts +++ b/lib/shopify/queries/collection.ts @@ -36,9 +36,9 @@ export const getCollectionsQuery = /* GraphQL */ ` `; export const getCollectionProductsQuery = /* GraphQL */ ` - query getCollectionProducts($handle: String!, $first: Int = 100) { + query getCollectionProducts($handle: String!) { collection(handle: $handle) { - products(first: $first) { + products(first: 100) { edges { node { ...product diff --git a/lib/shopify/types.ts b/lib/shopify/types.ts index d4e7a6c4d..aca4c413b 100644 --- a/lib/shopify/types.ts +++ b/lib/shopify/types.ts @@ -199,7 +199,6 @@ export type ShopifyCollectionProductsOperation = { }; variables: { handle: string; - first?: number; }; };