mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
rename checkoutCreate to createCart and remove Shopify checkout API
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
32
framework/reactioncommerce/cart/utils/create-cart.ts
Normal file
32
framework/reactioncommerce/cart/utils/create-cart.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
REACTION_ANONYMOUS_CART_TOKEN_COOKIE,
|
||||
SHOPIFY_CHECKOUT_URL_COOKIE,
|
||||
REACTION_COOKIE_EXPIRE,
|
||||
} from '../../const'
|
||||
import createCartMutation from '../../utils/mutations/create-cart'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
export const createCart = async (fetch: any) => {
|
||||
const data = await fetch({
|
||||
query: createCartMutation,
|
||||
variables: {
|
||||
input: {
|
||||
shopId,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const checkout = data.checkoutCreate?.checkout
|
||||
const checkoutId = checkout?.id
|
||||
|
||||
if (checkoutId) {
|
||||
const options = {
|
||||
expires: REACTION_COOKIE_EXPIRE,
|
||||
}
|
||||
Cookies.set(REACTION_ANONYMOUS_CART_TOKEN_COOKIE, checkoutId, options)
|
||||
}
|
||||
|
||||
return checkout
|
||||
}
|
||||
|
||||
export default createCart
|
Reference in New Issue
Block a user