mirror of
https://github.com/vercel/commerce.git
synced 2025-06-28 09:21:22 +00:00
feat: reshape products
This commit is contained in:
parent
1cd708309d
commit
c4ab3aba8d
@ -28,8 +28,8 @@ export async function generateMetadata({
|
|||||||
const hide = !product.tags.includes(HIDDEN_PRODUCT_TAG);
|
const hide = !product.tags.includes(HIDDEN_PRODUCT_TAG);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: product.seo.title || product.title,
|
title: product.seo?.title || product.title,
|
||||||
description: product.seo.description || product.description,
|
description: product.seo?.description || product.description,
|
||||||
robots: {
|
robots: {
|
||||||
index: hide,
|
index: hide,
|
||||||
follow: hide,
|
follow: hide,
|
||||||
@ -61,6 +61,7 @@ export default async function ProductPage({ params }: { params: { handle: string
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="lg:grid lg:grid-cols-6">
|
<div className="lg:grid lg:grid-cols-6">
|
||||||
|
{product.images && (
|
||||||
<div className="lg:col-span-4">
|
<div className="lg:col-span-4">
|
||||||
<Gallery
|
<Gallery
|
||||||
title={product.title}
|
title={product.title}
|
||||||
@ -68,10 +69,11 @@ export default async function ProductPage({ params }: { params: { handle: string
|
|||||||
currencyCode={product.priceRange.maxVariantPrice.currencyCode}
|
currencyCode={product.priceRange.maxVariantPrice.currencyCode}
|
||||||
images={product.images.map((image: Image) => ({
|
images={product.images.map((image: Image) => ({
|
||||||
src: image.url,
|
src: image.url,
|
||||||
altText: image.altText
|
altText: image.altText ?? ''
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="p-6 lg:col-span-2">
|
<div className="p-6 lg:col-span-2">
|
||||||
{/* @ts-expect-error Server Component */}
|
{/* @ts-expect-error Server Component */}
|
||||||
|
@ -66,9 +66,6 @@ const reshapeCart = (cart: MedusaCart): Cart => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const reshapeProduct = (product: MedusaProduct): Product => {
|
const reshapeProduct = (product: MedusaProduct): Product => {
|
||||||
const featuredImage = {
|
|
||||||
url: product.images?.[0]?.url ?? ''
|
|
||||||
};
|
|
||||||
const priceRange = {
|
const priceRange = {
|
||||||
maxVariantPrice: {
|
maxVariantPrice: {
|
||||||
amount: product.variants?.[0]?.prices?.[0]?.amount.toString() ?? '',
|
amount: product.variants?.[0]?.prices?.[0]?.amount.toString() ?? '',
|
||||||
@ -76,12 +73,22 @@ const reshapeProduct = (product: MedusaProduct): Product => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const updatedAt = product.updated_at;
|
const updatedAt = product.updated_at;
|
||||||
|
const tags = product.tags?.map((tag) => tag.value) || [];
|
||||||
|
const descriptionHtml = product.description ?? '';
|
||||||
|
const featuredImage = {
|
||||||
|
url: product.images?.[0]?.url ?? '',
|
||||||
|
altText: product.images?.[0]?.id ?? ''
|
||||||
|
};
|
||||||
|
const availableForSale = true;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...product,
|
...product,
|
||||||
featuredImage,
|
featuredImage,
|
||||||
priceRange,
|
priceRange,
|
||||||
updatedAt
|
updatedAt,
|
||||||
|
tags,
|
||||||
|
descriptionHtml,
|
||||||
|
availableForSale
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ export type MedusaProduct = {
|
|||||||
handle?: string | null;
|
handle?: string | null;
|
||||||
is_giftcard: boolean;
|
is_giftcard: boolean;
|
||||||
status?: 'draft' | 'proposed' | 'published' | 'rejected';
|
status?: 'draft' | 'proposed' | 'published' | 'rejected';
|
||||||
images?: Array<Image>;
|
images?: Array<MedusaImage>;
|
||||||
thumbnail?: string | null;
|
thumbnail?: string | null;
|
||||||
options?: Array<ProductOption>;
|
options?: Array<ProductOption>;
|
||||||
variants?: Array<ProductVariant>;
|
variants: Array<ProductVariant>;
|
||||||
categories?: Array<ProductCategory>;
|
categories?: Array<ProductCategory>;
|
||||||
profile_id?: string | null;
|
profile_id?: string | null;
|
||||||
profile?: ShippingProfile | null;
|
profile?: ShippingProfile | null;
|
||||||
@ -49,11 +49,14 @@ export type MedusaProduct = {
|
|||||||
deleted_at: Date | null;
|
deleted_at: Date | null;
|
||||||
type_id: string;
|
type_id: string;
|
||||||
material?: string | null;
|
material?: string | null;
|
||||||
|
tags?: ProductTag[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Product = MedusaProduct & {
|
export type Product = Omit<MedusaProduct, 'tags'> & {
|
||||||
featuredImage: {
|
featuredImage: FeaturedImage;
|
||||||
url: string;
|
seo?: {
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
};
|
};
|
||||||
priceRange: {
|
priceRange: {
|
||||||
maxVariantPrice: {
|
maxVariantPrice: {
|
||||||
@ -62,9 +65,28 @@ export type Product = MedusaProduct & {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
descriptionHtml: string;
|
||||||
|
tags: Array<string>;
|
||||||
|
availableForSale: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Image = {
|
export type FeaturedImage = {
|
||||||
|
url: string;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
altText: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ProductTag = {
|
||||||
|
id: string;
|
||||||
|
value: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
deleted_at: string | null;
|
||||||
|
metadata?: Record<string, unknown> | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type MedusaImage = {
|
||||||
id: string;
|
id: string;
|
||||||
url: string;
|
url: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
@ -73,6 +95,10 @@ export type Image = {
|
|||||||
metadata?: { [key: string]: string } | null;
|
metadata?: { [key: string]: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Image = MedusaImage & {
|
||||||
|
altText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type ShippingProfile = {
|
export type ShippingProfile = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user