mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
Fix kibocommerce & commercejs
This commit is contained in:
parent
261442d49d
commit
6d289d1b5e
@ -9,6 +9,6 @@ export function normalizeCategory(
|
|||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
path: slug,
|
path: `/${slug}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,51 @@
|
|||||||
import type { PrCategory, CustomerAccountInput, Document } from '../../schema'
|
import type {
|
||||||
import { Page } from '../types/page'
|
PrCategory,
|
||||||
import { Customer } from '../types/customer'
|
CustomerAccountInput,
|
||||||
import { WishlistItem } from '@vercel/commerce/types/wishlist'
|
Document,
|
||||||
|
Product as KiboProduct,
|
||||||
|
} from '../../schema'
|
||||||
|
|
||||||
export function normalizeProduct(productNode: any, config: any): any {
|
import type { Page } from '@vercel/commerce/types/page'
|
||||||
|
import type { Category } from '@vercel/commerce/types/site'
|
||||||
|
import type { Product } from '@vercel/commerce/types/product'
|
||||||
|
import type { Customer } from '@vercel/commerce/types/customer'
|
||||||
|
import type { Cart, LineItem } from '@vercel/commerce/types/cart'
|
||||||
|
import type { WishlistItem } from '@vercel/commerce/types/wishlist'
|
||||||
|
|
||||||
|
export function normalizeProduct(
|
||||||
|
productNode: KiboProduct,
|
||||||
|
config: any
|
||||||
|
): Product {
|
||||||
const product = {
|
const product = {
|
||||||
id: productNode.productCode,
|
id: productNode.productCode || '',
|
||||||
name: productNode.content.productName,
|
name: productNode.content?.productName || '',
|
||||||
vendor: '',
|
vendor: '',
|
||||||
path: `/${productNode.productCode}`,
|
path: `/${productNode.productCode}`,
|
||||||
slug: productNode.productCode,
|
slug: productNode.productCode || '',
|
||||||
price: {
|
price: {
|
||||||
value: productNode?.price?.price,
|
value: productNode?.price?.price ?? 0,
|
||||||
currencyCode: config.currencyCode,
|
currencyCode: config.currencyCode,
|
||||||
},
|
},
|
||||||
descriptionHtml: productNode.content.productShortDescription,
|
description: productNode.content?.productFullDescription || '',
|
||||||
|
descriptionHtml: productNode.content?.productFullDescription || '',
|
||||||
images: productNode.content.productImages.map((p: any) => ({
|
images:
|
||||||
url: `http:${p.imageUrl}`,
|
productNode.content?.productImages?.map((p: any) => ({
|
||||||
altText: p.imageLabel,
|
url: `http:${p.imageUrl}`,
|
||||||
})),
|
altText: p.imageLabel,
|
||||||
|
})) || [],
|
||||||
variants: productNode.variations?.map((v: any) => ({
|
variants:
|
||||||
id: v.productCode,
|
productNode.variations?.map((v: any) => ({
|
||||||
options: v.options.map((o: any) => ({
|
id: v.productCode,
|
||||||
['__typename']: 'MultipleChoiceOption',
|
options:
|
||||||
id: o.attributeFQN,
|
v.options?.map((o: any) => ({
|
||||||
displayName:
|
['__typename']: 'MultipleChoiceOption',
|
||||||
o.attributeFQN.split('~')[1][0].toUpperCase() +
|
id: o.attributeFQN,
|
||||||
o.attributeFQN.split('~')[1].slice(1).toLowerCase(),
|
displayName:
|
||||||
values: [{ label: o.value.toString() }],
|
o.attributeFQN.split('~')[1][0].toUpperCase() +
|
||||||
})),
|
o.attributeFQN.split('~')[1].slice(1).toLowerCase(),
|
||||||
})) || [
|
values: [{ label: o.value.toString() }],
|
||||||
{
|
})) ?? [],
|
||||||
id: '',
|
})) ?? [],
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
options:
|
options:
|
||||||
productNode.options?.map((o: any) => ({
|
productNode.options?.map((o: any) => ({
|
||||||
id: o.attributeFQN,
|
id: o.attributeFQN,
|
||||||
@ -44,7 +53,7 @@ export function normalizeProduct(productNode: any, config: any): any {
|
|||||||
values: o.values.map((v: any) => ({
|
values: o.values.map((v: any) => ({
|
||||||
label: v.value.toString(),
|
label: v.value.toString(),
|
||||||
})),
|
})),
|
||||||
})) || [],
|
})) ?? [],
|
||||||
}
|
}
|
||||||
|
|
||||||
return product
|
return product
|
||||||
@ -61,7 +70,7 @@ export function normalizePage(page: Document): Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeCart(data: any): any {
|
export function normalizeCart(data: any): Cart {
|
||||||
return {
|
return {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
customerId: data.userId,
|
customerId: data.userId,
|
||||||
@ -95,7 +104,7 @@ export function normalizeCustomer(customer: CustomerAccountInput): Customer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeLineItem(item: any): any {
|
function normalizeLineItem(item: any): LineItem {
|
||||||
return {
|
return {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
variantId: item.product.variationProductCode,
|
variantId: item.product.variationProductCode,
|
||||||
@ -113,7 +122,7 @@ function normalizeLineItem(item: any): any {
|
|||||||
price: item?.unitPrice.extendedAmount,
|
price: item?.unitPrice.extendedAmount,
|
||||||
listPrice: 0,
|
listPrice: 0,
|
||||||
},
|
},
|
||||||
options: item.product.options,
|
options: item.product.options ?? [],
|
||||||
path: `${item.product.productCode}`,
|
path: `${item.product.productCode}`,
|
||||||
discounts: item?.discounts?.map((discount: any) => ({
|
discounts: item?.discounts?.map((discount: any) => ({
|
||||||
value: discount.discounted_amount,
|
value: discount.discounted_amount,
|
||||||
@ -121,11 +130,11 @@ function normalizeLineItem(item: any): any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeCategory(category: PrCategory): any {
|
export function normalizeCategory(category: PrCategory): Category {
|
||||||
return {
|
return {
|
||||||
id: category?.categoryCode,
|
id: category?.categoryCode || '',
|
||||||
name: category?.content?.name,
|
name: category?.content?.name || '',
|
||||||
slug: category?.content?.slug,
|
slug: category?.content?.slug || '',
|
||||||
path: `/${category?.content?.slug}`,
|
path: `/${category?.content?.slug}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,7 +184,7 @@ function getProuducts(item: any, config: any): any {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
options: item.product.options,
|
options: item.product.options ?? [],
|
||||||
path: `/${item.product.productCode}`,
|
path: `/${item.product.productCode}`,
|
||||||
description: item.product.description,
|
description: item.product.description,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user