mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
convert sylius product to commerce product
This commit is contained in:
parent
b414f4f708
commit
b4c088f4ca
@ -1,4 +1,5 @@
|
|||||||
export { default as handleFetchResponse } from './handle-fetch-response'
|
export { default as handleFetchResponse } from './handle-fetch-response'
|
||||||
|
export * from './normalize'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
export { default as getSearchVariables } from './get-search-variables'
|
export { default as getSearchVariables } from './get-search-variables'
|
||||||
@ -13,6 +14,5 @@ export { default as handleAccountActivation } from './handle-account-activation'
|
|||||||
export { default as throwUserErrors } from './throw-user-errors'
|
export { default as throwUserErrors } from './throw-user-errors'
|
||||||
export * from './queries'
|
export * from './queries'
|
||||||
export * from './mutations'
|
export * from './mutations'
|
||||||
export * from './normalize'
|
|
||||||
export * from './customer-token'
|
export * from './customer-token'
|
||||||
*/
|
*/
|
||||||
|
55
packages/sylius/src/utils/normalize.ts
Normal file
55
packages/sylius/src/utils/normalize.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import {
|
||||||
|
Product,
|
||||||
|
ProductImage,
|
||||||
|
ProductPrice,
|
||||||
|
ProductVariant,
|
||||||
|
} from '@vercel/commerce/types/product'
|
||||||
|
import {
|
||||||
|
SyliusProduct,
|
||||||
|
SyliusProductImage,
|
||||||
|
SyliusProductVariant,
|
||||||
|
} from '../types'
|
||||||
|
|
||||||
|
export const normalizeProduct = (product: SyliusProduct): Product => {
|
||||||
|
return {
|
||||||
|
id: product.id.toString(),
|
||||||
|
name: product.name,
|
||||||
|
description: product.description,
|
||||||
|
images: product.images.map((image) => normalizeProductImage(image)),
|
||||||
|
variants: product.variants.map((variant) =>
|
||||||
|
normalizeProductVariant(variant)
|
||||||
|
),
|
||||||
|
price: normalizeProductPrice(
|
||||||
|
product.variants[0].price,
|
||||||
|
product.variants[0].originalPrice
|
||||||
|
),
|
||||||
|
options: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeProductVariant = (
|
||||||
|
variant: SyliusProductVariant
|
||||||
|
): ProductVariant => {
|
||||||
|
return {
|
||||||
|
id: variant.id,
|
||||||
|
options: [],
|
||||||
|
availableForSale: variant.inStock,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeProductImage = (image: SyliusProductImage): ProductImage => {
|
||||||
|
return {
|
||||||
|
url: process.env.NEXT_PUBLIC_SYLIUS_ALLOWED_IMAGE_URL + image.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeProductPrice = (
|
||||||
|
price: number,
|
||||||
|
originalPrice: number
|
||||||
|
): ProductPrice => {
|
||||||
|
return {
|
||||||
|
value: originalPrice / 100,
|
||||||
|
salePrice: price / 100,
|
||||||
|
currencyCode: 'EUR',
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user