diff --git a/app/search/[collection]/page.tsx b/app/search/[collection]/page.tsx index 67c668ea6..cfbcdb31a 100644 --- a/app/search/[collection]/page.tsx +++ b/app/search/[collection]/page.tsx @@ -96,8 +96,7 @@ export default async function CategorySearchPage(props: { }) { const collectionHandle = props.params.collection; - const manufacturerVariant = - Object.keys(manufactureVariantMap).find((key) => collectionHandle.startsWith(key)) || 'engines'; + const [partType, make] = collectionHandle.split('_'); return ( <> @@ -158,10 +157,11 @@ export default async function CategorySearchPage(props: { )} - - - - + {!make ? ( + + + + ) : null} ); } diff --git a/components/plp/content.tsx b/components/plp/content.tsx index 75af208ce..ed2aaa6ab 100644 --- a/components/plp/content.tsx +++ b/components/plp/content.tsx @@ -1,26 +1,19 @@ -import { getMetaobject } from 'lib/shopify'; +import { getCollection, getMetaobject } from 'lib/shopify'; import DefaultContent from './default-content'; import DynamicContent from './dynamic-content'; const Content = async ({ collection }: { collection: string }) => { - const [lastSegment] = collection.split('_').slice(-1); + const collectionData = await getCollection({ handle: collection }); - if (!lastSegment) { + if (!collectionData) { + return null; + } + + if (!collectionData.dynamicContent) { return ; } - let content = null; - - if (collection.startsWith('transmissions')) { - content = await getMetaobject({ - handle: { handle: `transmission_code_${lastSegment}`, type: 'plp_content' } - }); - } else if (collection.startsWith('engines')) { - content = await getMetaobject({ - handle: { handle: `engine_size_${lastSegment}`, type: 'plp_content' } - }); - } - + const content = await getMetaobject({ id: collectionData.dynamicContent }); if (!content) { return ; } diff --git a/components/plp/tabs.tsx b/components/plp/tabs.tsx index 5be0546ed..bd2025a41 100644 --- a/components/plp/tabs.tsx +++ b/components/plp/tabs.tsx @@ -7,7 +7,7 @@ const TabPanelContent = async ({ ids }: { ids: string[] }) => { const content = await getMetaobjectsByIds(ids); return ( - + {content.map((block) => ( ))} diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index df922c2a5..3e200ecac 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -358,6 +358,7 @@ const reshapeCollection = (collection: ShopifyCollection): Collection | undefine ...collection, helpfulLinks: parseMetaFieldValue(collection.helpfulLinks), helpfulLinksTop: parseMetaFieldValue(collection.helpfulLinksTop), + dynamicContent: collection.dynamicContent?.value || null, path: getCollectionUrl(collection.handle) }; }; diff --git a/lib/shopify/queries/collection.ts b/lib/shopify/queries/collection.ts index 014fd7dce..4e50f8d03 100644 --- a/lib/shopify/queries/collection.ts +++ b/lib/shopify/queries/collection.ts @@ -15,6 +15,9 @@ const collectionFragment = /* GraphQL */ ` helpfulLinksTop: metafield(namespace: "custom", key: "helpful_links_top") { value } + dynamicContent: metafield(namespace: "custom", key: "plp_content") { + value + } updatedAt } ${seoFragment} diff --git a/lib/shopify/types.ts b/lib/shopify/types.ts index 194952b1e..2c09088ff 100644 --- a/lib/shopify/types.ts +++ b/lib/shopify/types.ts @@ -42,10 +42,14 @@ export type CartItem = { addOnProduct?: CartItem & { quantity: number }; }; -export type Collection = Omit & { +export type Collection = Omit< + ShopifyCollection, + 'helpfulLinks' | 'helpfulLinksTop' | 'dynamicContent' +> & { path: string; helpfulLinks: string[] | null; helpfulLinksTop: string[] | null; + dynamicContent: string | null; }; export type Customer = { @@ -513,6 +517,7 @@ export type ShopifyCollection = { updatedAt: string; helpfulLinks: { value: string } | null; helpfulLinksTop: { value: string } | null; + dynamicContent: { value: string } | null; }; export type ShopifyProduct = {