mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 07:45:53 +00:00
* fix update cart item * update types * update checkout * update get-page, cleanup types * revert change to incorrect file * cleanup Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
29 lines
503 B
TypeScript
29 lines
503 B
TypeScript
import { SWELL_CHECKOUT_URL_COOKIE } from '../../const'
|
|
|
|
import Cookies from 'js-cookie'
|
|
|
|
export const checkoutCreate = async (fetch: any) => {
|
|
const cart = await fetch({
|
|
query: 'cart',
|
|
method: 'get',
|
|
})
|
|
|
|
if (!cart) {
|
|
await fetch({
|
|
query: 'cart',
|
|
method: 'setItems',
|
|
variables: [[]],
|
|
})
|
|
}
|
|
|
|
const checkoutUrl = cart?.checkout_url
|
|
|
|
if (checkoutUrl) {
|
|
Cookies.set(SWELL_CHECKOUT_URL_COOKIE, checkoutUrl)
|
|
}
|
|
|
|
return cart
|
|
}
|
|
|
|
export default checkoutCreate
|