mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 01:05:53 +00:00
* 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>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import type { Cart, OrdercloudCart, OrdercloudLineItem } from '../../types/cart'
|
|
|
|
export function formatCart(
|
|
cart: OrdercloudCart,
|
|
lineItems: OrdercloudLineItem[]
|
|
): Cart {
|
|
return {
|
|
id: cart.ID,
|
|
customerId: cart.FromUserID,
|
|
email: cart.FromUser.Email,
|
|
createdAt: cart.DateCreated,
|
|
currency: {
|
|
code: cart.FromUser?.xp?.currency ?? 'USD',
|
|
},
|
|
taxesIncluded: cart.TaxCost === 0,
|
|
lineItems: lineItems.map((lineItem) => ({
|
|
id: lineItem.ID,
|
|
variantId: lineItem.Variant ? String(lineItem.Variant.ID) : '',
|
|
productId: lineItem.ProductID,
|
|
name: lineItem.Product.Name,
|
|
quantity: lineItem.Quantity,
|
|
discounts: [],
|
|
path: lineItem.ProductID,
|
|
variant: {
|
|
id: lineItem.Variant ? String(lineItem.Variant.ID) : '',
|
|
sku: lineItem.ID,
|
|
name: lineItem.Product.Name,
|
|
image: {
|
|
url: lineItem.Product.xp?.Images?.[0]?.url,
|
|
},
|
|
requiresShipping: Boolean(lineItem.ShippingAddress),
|
|
price: lineItem.UnitPrice,
|
|
listPrice: lineItem.UnitPrice,
|
|
},
|
|
})),
|
|
lineItemsSubtotalPrice: cart.Subtotal,
|
|
subtotalPrice: cart.Subtotal,
|
|
totalPrice: cart.Total,
|
|
discounts: [],
|
|
}
|
|
}
|