mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
Implement cart
This commit is contained in:
41
framework/ordercloud/api/utils/cart.ts
Normal file
41
framework/ordercloud/api/utils/cart.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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: [],
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user