mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 04:37:51 +00:00
link dynamic content to a collection
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
parent
ebbc8f053c
commit
d8e7553918
@ -96,8 +96,7 @@ export default async function CategorySearchPage(props: {
|
|||||||
}) {
|
}) {
|
||||||
const collectionHandle = props.params.collection;
|
const collectionHandle = props.params.collection;
|
||||||
|
|
||||||
const manufacturerVariant =
|
const [partType, make] = collectionHandle.split('_');
|
||||||
Object.keys(manufactureVariantMap).find((key) => collectionHandle.startsWith(key)) || 'engines';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -158,10 +157,11 @@ export default async function CategorySearchPage(props: {
|
|||||||
<EngineSizes collectionHandle={collectionHandle} />
|
<EngineSizes collectionHandle={collectionHandle} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
)}
|
)}
|
||||||
|
{!make ? (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<Manufacturers variant={manufactureVariantMap[manufacturerVariant]} />
|
<Manufacturers variant={manufactureVariantMap[partType || 'engines']} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,19 @@
|
|||||||
import { getMetaobject } from 'lib/shopify';
|
import { getCollection, getMetaobject } from 'lib/shopify';
|
||||||
import DefaultContent from './default-content';
|
import DefaultContent from './default-content';
|
||||||
import DynamicContent from './dynamic-content';
|
import DynamicContent from './dynamic-content';
|
||||||
|
|
||||||
const Content = async ({ collection }: { collection: string }) => {
|
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 <DefaultContent />;
|
return <DefaultContent />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = null;
|
const content = await getMetaobject({ id: collectionData.dynamicContent });
|
||||||
|
|
||||||
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' }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
return <DefaultContent />;
|
return <DefaultContent />;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ const TabPanelContent = async ({ ids }: { ids: string[] }) => {
|
|||||||
const content = await getMetaobjectsByIds(ids);
|
const content = await getMetaobjectsByIds(ids);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabPanel className="flex min-w-full space-y-5">
|
<TabPanel className="flex min-w-full flex-col space-y-5">
|
||||||
{content.map((block) => (
|
{content.map((block) => (
|
||||||
<PageContent key={block.id} block={block} />
|
<PageContent key={block.id} block={block} />
|
||||||
))}
|
))}
|
||||||
|
@ -358,6 +358,7 @@ const reshapeCollection = (collection: ShopifyCollection): Collection | undefine
|
|||||||
...collection,
|
...collection,
|
||||||
helpfulLinks: parseMetaFieldValue<string[]>(collection.helpfulLinks),
|
helpfulLinks: parseMetaFieldValue<string[]>(collection.helpfulLinks),
|
||||||
helpfulLinksTop: parseMetaFieldValue<string[]>(collection.helpfulLinksTop),
|
helpfulLinksTop: parseMetaFieldValue<string[]>(collection.helpfulLinksTop),
|
||||||
|
dynamicContent: collection.dynamicContent?.value || null,
|
||||||
path: getCollectionUrl(collection.handle)
|
path: getCollectionUrl(collection.handle)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -15,6 +15,9 @@ const collectionFragment = /* GraphQL */ `
|
|||||||
helpfulLinksTop: metafield(namespace: "custom", key: "helpful_links_top") {
|
helpfulLinksTop: metafield(namespace: "custom", key: "helpful_links_top") {
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
dynamicContent: metafield(namespace: "custom", key: "plp_content") {
|
||||||
|
value
|
||||||
|
}
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
${seoFragment}
|
${seoFragment}
|
||||||
|
@ -42,10 +42,14 @@ export type CartItem = {
|
|||||||
addOnProduct?: CartItem & { quantity: number };
|
addOnProduct?: CartItem & { quantity: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Collection = Omit<ShopifyCollection, 'helpfulLinks' | 'helpfulLinksTop'> & {
|
export type Collection = Omit<
|
||||||
|
ShopifyCollection,
|
||||||
|
'helpfulLinks' | 'helpfulLinksTop' | 'dynamicContent'
|
||||||
|
> & {
|
||||||
path: string;
|
path: string;
|
||||||
helpfulLinks: string[] | null;
|
helpfulLinks: string[] | null;
|
||||||
helpfulLinksTop: string[] | null;
|
helpfulLinksTop: string[] | null;
|
||||||
|
dynamicContent: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Customer = {
|
export type Customer = {
|
||||||
@ -513,6 +517,7 @@ export type ShopifyCollection = {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
helpfulLinks: { value: string } | null;
|
helpfulLinks: { value: string } | null;
|
||||||
helpfulLinksTop: { value: string } | null;
|
helpfulLinksTop: { value: string } | null;
|
||||||
|
dynamicContent: { value: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ShopifyProduct = {
|
export type ShopifyProduct = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user