add PDP content

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe
2024-07-07 11:09:24 +07:00
parent fab2a5e967
commit cc2c79764d
15 changed files with 76 additions and 270 deletions

View File

@@ -9,6 +9,7 @@ const productFragment = /* GraphQL */ `
title
description
descriptionHtml
productType
options {
id
name

View File

@@ -522,6 +522,7 @@ export type ShopifyProduct = {
title: string;
description: string;
descriptionHtml: string;
productType: string;
options: ProductOption[];
priceRange: {
maxVariantPrice: Money;

View File

@@ -18,6 +18,9 @@ export const carPartPlanetColor = {
200: '#666C89',
500: '#2D3A7B',
600: '#111C55'
},
black: {
700: '#1A1A25'
}
};
@@ -41,6 +44,9 @@ export const remanTransmissionColor = {
200: '#666C89',
500: '#2D3A7B',
600: '#111C55'
},
black: {
700: '#1A1A25'
}
};
@@ -64,5 +70,8 @@ export const transmissionLocatorColor = {
200: '#666C89',
500: '#2D3A7B',
600: '#111C55'
},
black: {
700: '#1A1A25'
}
};

View File

@@ -1,7 +1,7 @@
import clsx, { ClassValue } from 'clsx';
import { ReadonlyURLSearchParams } from 'next/navigation';
import { twMerge } from 'tailwind-merge';
import { Menu } from './shopify/types';
import { Menu, Product, ProductVariant } from './shopify/types';
export function cx(...args: ClassValue[]) {
return twMerge(clsx(...args));
@@ -149,3 +149,19 @@ export const getCollectionUrl = (handle: string, includeSlashPrefix = true) => {
return includeSlashPrefix ? `/${rewriteUrl}` : rewriteUrl;
};
export const getSelectedProductVariant = ({
product,
searchParams
}: {
product: Product;
searchParams?: { [key: string]: string | string[] | undefined };
}) => {
const variant = product.variants.find((variant: ProductVariant) =>
variant.selectedOptions.every(
(option) => option.value === searchParams?.[option.name.toLowerCase()]
)
);
return variant || product.variants[0];
};