add default content for PLP page

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe 2024-07-10 08:49:36 +07:00
parent 4738600b4d
commit 631d861324
No known key found for this signature in database
GPG Key ID: CFD53CE570D42DF5
2 changed files with 20 additions and 4 deletions

View File

@ -5,12 +5,12 @@ import DynamicContent from './dynamic-content';
const Content = async ({ collection }: { collection: Collection }) => {
if (!collection.dynamicContent) {
return <DefaultContent />;
return <DefaultContent collection={collection} />;
}
const content = await getMetaobject({ id: collection.dynamicContent });
if (!content) {
return <DefaultContent />;
return <DefaultContent collection={collection} />;
}
return <DynamicContent content={content} />;

View File

@ -1,11 +1,27 @@
import Tag from 'components/tag';
import { getMetaobject } from 'lib/shopify';
import { Collection } from 'lib/shopify/types';
import { Suspense } from 'react';
import Tabs, { TabsPlaceholder } from './tabs';
const DefaultContent = async () => {
const DefaultContent = async ({ collection }: { collection: Collection }) => {
let handle = 'default-plp-content';
if (collection.handle.startsWith('transmissions')) {
handle = 'transmissions-plp-content';
}
if (
collection.handle.startsWith('engines') ||
collection.handle.startsWith('remanufactured-engines')
) {
handle = 'engines-plp-content';
}
if (collection.handle.startsWith('transfer-cases')) {
handle = 'transfer-cases-plp-content';
}
const defaultPLPContent = await getMetaobject({
handle: { handle: 'default-plp-content', type: 'plp_content' }
handle: { handle, type: 'plp_content' }
});
if (!defaultPLPContent) {