From da11c82b7bc3afca2695bc463361d184bc2f8967 Mon Sep 17 00:00:00 2001 From: Leah Wagner Date: Sun, 8 Nov 2020 14:36:23 -0800 Subject: [PATCH] Filter products from the homepage grid display when they do not have and image. Provide a fallback/placeholder image for the ProductCard for when a product does not have an image. --- components/product/ProductCard/ProductCard.tsx | 4 ++-- pages/index.tsx | 2 ++ public/product-img-placeholder.svg | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 public/product-img-placeholder.svg diff --git a/components/product/ProductCard/ProductCard.tsx b/components/product/ProductCard/ProductCard.tsx index 85e69b3f2..5377511f0 100644 --- a/components/product/ProductCard/ProductCard.tsx +++ b/components/product/ProductCard/ProductCard.tsx @@ -58,7 +58,7 @@ const ProductCard: FC = ({ layout={imgLayout} loading={imgLoading} priority={imgPriority} - src={p.images.edges?.[0]?.node.urlOriginal!} + src={p.images.edges?.[0]?.node.urlOriginal! || '/product-img-placeholder.svg'} alt={p.images.edges?.[0]?.node.altText || 'Product Image'} /> @@ -81,7 +81,7 @@ const ProductCard: FC = ({
{p.name} { // Create a copy of products that we can mutate + // Filter products that do not have images const products = [...newestProducts] + .filter((p) => p.node.images.edges!.length > 0) // If the lists of featured and best selling products don't have enough // products, then fill them with products from the products list, this // is useful for new commerce sites that don't have a lot of products diff --git a/public/product-img-placeholder.svg b/public/product-img-placeholder.svg new file mode 100644 index 000000000..fbb43bb62 --- /dev/null +++ b/public/product-img-placeholder.svg @@ -0,0 +1,7 @@ + + + + + + +