forked from crowetic/commerce
.vscode
assets
components
config
framework
bigcommerce
commerce
local
ordercloud
api
endpoints
operations
utils
cart.ts
fetch-graphql.ts
fetch-rest.ts
index.ts
auth
cart
checkout
customer
product
types
utils
wishlist
.env.template
README.md
commerce.config.json
constants.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
saleor
shopify
swell
vendure
lib
pages
public
.editorconfig
.env.template
.eslintrc
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package-lock.json
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
* 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: [],
|
|
}
|
|
}
|