diff --git a/app/product/[handle]/page.tsx b/app/product/[handle]/page.tsx index 94a8d74f0..8a9ef69b5 100644 --- a/app/product/[handle]/page.tsx +++ b/app/product/[handle]/page.tsx @@ -132,11 +132,7 @@ async function RelatedProducts({ id }: { id: string }) { > diff --git a/components/grid/tile.tsx b/components/grid/tile.tsx index 08d5ff34e..a8abf656f 100644 --- a/components/grid/tile.tsx +++ b/components/grid/tile.tsx @@ -1,25 +1,23 @@ import { ArrowRightIcon, PhotoIcon } from '@heroicons/react/24/solid'; import clsx from 'clsx'; import Price from 'components/price'; +import { Product } from 'lib/shopify/types'; import Image from 'next/image'; import Link from 'next/link'; export function GridTileImage({ active, - label, + product, href, - place = 'grid', ...props }: { active?: boolean; - label?: { - title: string; - amount: string; - currencyCode: string; - }; - place?: 'grid' | 'gallery'; + product: Product; href: string; } & React.ComponentProps) { + const metafieldKeys = ['engineCylinders', 'fuelType'] as Partial[]; + const shouldShowDescription = metafieldKeys.some((key) => product[key]); + return ( @@ -43,30 +41,57 @@ export function GridTileImage({ )} - - {label && ( - {label.title} - )} - {label && ( - - - - )} + + {product.title} + + + + {shouldShowDescription && ( + + {product.engineCylinders?.length ? ( + + + {`${product.engineCylinders[0]} Cylinder`} + + ) : null} + {product.fuelType ? ( + + + {product.fuelType} + + ) : null} + + )} + + - {place === 'grid' && ( - - More details - - - )} + + + More details + + ); } diff --git a/components/layout/products-list/index.tsx b/components/layout/products-list/index.tsx index b17d2ce13..1eb6fae6a 100644 --- a/components/layout/products-list/index.tsx +++ b/components/layout/products-list/index.tsx @@ -70,11 +70,7 @@ const ProductsList = ({ > (product.engineCylinders), + fuelType: product.fuelType?.value || null, images: reshapeImages(images, product.title), variants: reshapeVariants(removeEdgesAndNodes(variants)) }; @@ -305,7 +307,6 @@ const reshapeProducts = (products: ShopifyProduct[]) => { for (const product of products) { if (product) { const reshapedProduct = reshapeProduct(product); - if (reshapedProduct) { reshapedProducts.push(reshapedProduct); } diff --git a/lib/shopify/types.ts b/lib/shopify/types.ts index d64376ba9..7443823c4 100644 --- a/lib/shopify/types.ts +++ b/lib/shopify/types.ts @@ -100,9 +100,14 @@ export type Metaobject = { [key: string]: string; }; -export type Product = Omit & { +export type Product = Omit< + ShopifyProduct, + 'variants' | 'images' | 'fuelType' | 'engineCylinders' +> & { variants: ProductVariant[]; images: Image[]; + fuelType: string | null; + engineCylinders: number[] | null; }; export type ProductOption = { @@ -128,6 +133,8 @@ export type ProductVariant = { mileage: number | null; estimatedDelivery: string | null; condition: string | null; + engineCylinders: string | null; + fuelType: string | null; }; export type ShopifyCartProductVariant = { @@ -205,6 +212,8 @@ export type ShopifyProduct = { handle: string; }[]; }; + engineCylinders: { value: string } | null; + fuelType: { value: string } | null; }; export type ShopifyCartOperation = { diff --git a/lib/utils.ts b/lib/utils.ts index 8d800e3f6..de885097e 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -51,7 +51,7 @@ export function normalizeUrl(domain: string, url: string) { export const parseMetaFieldValue = (field: { value: string } | null): T | null => { try { - return JSON.parse(field?.value || '{}'); + return field?.value ? JSON.parse(field.value) : null; } catch (error) { return null; } diff --git a/public/icons/cylinder.png b/public/icons/cylinder.png new file mode 100644 index 000000000..0e7b1a279 Binary files /dev/null and b/public/icons/cylinder.png differ diff --git a/public/icons/fuel.png b/public/icons/fuel.png new file mode 100644 index 000000000..14c9e5618 Binary files /dev/null and b/public/icons/fuel.png differ