mirror of
https://github.com/vercel/commerce.git
synced 2025-07-24 10:41:23 +00:00
feat: reshape products
This commit is contained in:
@@ -66,9 +66,6 @@ const reshapeCart = (cart: MedusaCart): Cart => {
|
||||
};
|
||||
|
||||
const reshapeProduct = (product: MedusaProduct): Product => {
|
||||
const featuredImage = {
|
||||
url: product.images?.[0]?.url ?? ''
|
||||
};
|
||||
const priceRange = {
|
||||
maxVariantPrice: {
|
||||
amount: product.variants?.[0]?.prices?.[0]?.amount.toString() ?? '',
|
||||
@@ -76,12 +73,22 @@ const reshapeProduct = (product: MedusaProduct): Product => {
|
||||
}
|
||||
};
|
||||
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 {
|
||||
...product,
|
||||
featuredImage,
|
||||
priceRange,
|
||||
updatedAt
|
||||
updatedAt,
|
||||
tags,
|
||||
descriptionHtml,
|
||||
availableForSale
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -27,10 +27,10 @@ export type MedusaProduct = {
|
||||
handle?: string | null;
|
||||
is_giftcard: boolean;
|
||||
status?: 'draft' | 'proposed' | 'published' | 'rejected';
|
||||
images?: Array<Image>;
|
||||
images?: Array<MedusaImage>;
|
||||
thumbnail?: string | null;
|
||||
options?: Array<ProductOption>;
|
||||
variants?: Array<ProductVariant>;
|
||||
variants: Array<ProductVariant>;
|
||||
categories?: Array<ProductCategory>;
|
||||
profile_id?: string | null;
|
||||
profile?: ShippingProfile | null;
|
||||
@@ -49,11 +49,14 @@ export type MedusaProduct = {
|
||||
deleted_at: Date | null;
|
||||
type_id: string;
|
||||
material?: string | null;
|
||||
tags?: ProductTag[];
|
||||
};
|
||||
|
||||
export type Product = MedusaProduct & {
|
||||
featuredImage: {
|
||||
url: string;
|
||||
export type Product = Omit<MedusaProduct, 'tags'> & {
|
||||
featuredImage: FeaturedImage;
|
||||
seo?: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
};
|
||||
priceRange: {
|
||||
maxVariantPrice: {
|
||||
@@ -62,9 +65,28 @@ export type Product = MedusaProduct & {
|
||||
};
|
||||
};
|
||||
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;
|
||||
url: string;
|
||||
created_at: string;
|
||||
@@ -73,6 +95,10 @@ export type Image = {
|
||||
metadata?: { [key: string]: string } | null;
|
||||
};
|
||||
|
||||
export type Image = MedusaImage & {
|
||||
altText?: string;
|
||||
};
|
||||
|
||||
export type ShippingProfile = {
|
||||
id: string;
|
||||
name: string;
|
||||
|
Reference in New Issue
Block a user