mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
setup swell checkout
This commit is contained in:
@@ -2,7 +2,7 @@ import useCart, { UseCart } from '@commerce/cart/use-cart'
|
||||
import { Cart } from '@commerce/types'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import { normalizeCart } from '../utils/normalize'
|
||||
// import { getCustomerQuery, getCustomerToken } from '../utils'
|
||||
import { checkoutCreate, checkoutToCart } from './utils'
|
||||
|
||||
export default useCart as UseCart<typeof handler>
|
||||
|
||||
@@ -12,10 +12,10 @@ export const handler: SWRHook<Cart | null> = {
|
||||
method: 'get',
|
||||
},
|
||||
async fetcher({ options, fetch }) {
|
||||
const data = await fetch<any | null>({
|
||||
...options,
|
||||
})
|
||||
return data ? normalizeCart(data) : null
|
||||
const cart = await checkoutCreate(fetch)
|
||||
|
||||
return cart ? normalizeCart(cart) : null
|
||||
// return checkoutToCart({ checkout } as any)
|
||||
},
|
||||
useHook: ({ useData }) => (input) => {
|
||||
return useData({
|
||||
|
@@ -1,10 +1,5 @@
|
||||
import {
|
||||
SHOPIFY_CHECKOUT_ID_COOKIE,
|
||||
SHOPIFY_CHECKOUT_URL_COOKIE,
|
||||
SHOPIFY_COOKIE_EXPIRE,
|
||||
} from '../../const'
|
||||
import { SWELL_CHECKOUT_URL_COOKIE } from '../../const'
|
||||
|
||||
// import checkoutCreateMutation from '../../utils/mutations/checkout-create'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
export const checkoutCreate = async (fetch: any) => {
|
||||
@@ -13,16 +8,11 @@ export const checkoutCreate = async (fetch: any) => {
|
||||
method: 'get',
|
||||
})
|
||||
|
||||
// const checkout = data.checkoutCreate?.checkout
|
||||
const checkoutId = cart?.id
|
||||
const checkoutUrl = cart?.checkout_url
|
||||
|
||||
// if (checkoutId) {
|
||||
// const options = {
|
||||
// expires: SHOPIFY_COOKIE_EXPIRE,
|
||||
// }
|
||||
// Cookies.set(SHOPIFY_CHECKOUT_ID_COOKIE, checkoutId, options)
|
||||
// Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout?.webUrl, options)
|
||||
// }
|
||||
if (checkoutUrl) {
|
||||
Cookies.set(SWELL_CHECKOUT_URL_COOKIE, checkoutUrl)
|
||||
}
|
||||
|
||||
return cart
|
||||
}
|
||||
|
Reference in New Issue
Block a user