mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
Add ordercloud provider (#500)
* Add ordercloud provider * Fix provider errors * Make submit checkout optional * Make submit checkout optional * Remove nullables when creating endpoint type * Update readme * Log checkout error * Log error * Save token to cookie * Update fetch rest * Use token at checkout Co-authored-by: Luis Alvarez <luis@vercel.com>
This commit is contained in:
47
framework/ordercloud/utils/product.ts
Normal file
47
framework/ordercloud/utils/product.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { Product } from '@commerce/types/product'
|
||||
|
||||
import type { RawProduct } from '../types/product'
|
||||
|
||||
export function normalize(product: RawProduct): Product {
|
||||
return {
|
||||
id: product.ID,
|
||||
name: product.Name,
|
||||
description: product.Description,
|
||||
slug: product.ID,
|
||||
images: product.xp.Images,
|
||||
price: {
|
||||
value: product.xp.Price,
|
||||
currencyCode: product.xp.PriceCurrency,
|
||||
},
|
||||
variants: product.xp.Variants?.length
|
||||
? product.xp.Variants.map((variant) => ({
|
||||
id: variant.ID,
|
||||
options: variant.Specs.map((spec) => ({
|
||||
id: spec.SpecID,
|
||||
__typename: 'MultipleChoiceOption',
|
||||
displayName: spec.Name,
|
||||
values: [
|
||||
{
|
||||
label: spec.Value,
|
||||
},
|
||||
],
|
||||
})),
|
||||
}))
|
||||
: [
|
||||
{
|
||||
id: '',
|
||||
options: [],
|
||||
},
|
||||
],
|
||||
options: product.xp.Specs?.length
|
||||
? product.xp.Specs.map((spec) => ({
|
||||
id: spec.ID,
|
||||
displayName: spec.Name,
|
||||
values: spec.Options.map((option) => ({
|
||||
label: option.Value,
|
||||
...(option.xp?.hexColor && { hexColors: [option.xp.hexColor] }),
|
||||
})),
|
||||
}))
|
||||
: [],
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user