diff --git a/framework/reactioncommerce/api/cart/handlers/add-item.ts b/framework/reactioncommerce/api/cart/handlers/add-item.ts index 202a14638..b2b61736a 100644 --- a/framework/reactioncommerce/api/cart/handlers/add-item.ts +++ b/framework/reactioncommerce/api/cart/handlers/add-item.ts @@ -1,7 +1,7 @@ import type { CartHandlers } from '..' import { addCartItemsMutation, - checkoutCreateMutation, + createCartMutation, } from '@framework/utils/mutations' import getCartCookie from '@framework/api/utils/get-cart-cookie' import { @@ -41,7 +41,7 @@ const addItem: CartHandlers['addItem'] = async ({ if (!item.quantity) item.quantity = 1 if (cartId === config.dummyEmptyCartId) { - const createdCart = await config.fetch(checkoutCreateMutation, { + const createdCart = await config.fetch(createCartMutation, { variables: { input: { shopId: config.shopId, diff --git a/framework/reactioncommerce/api/checkout/index.ts b/framework/reactioncommerce/api/checkout/index.ts index 1fe5fb6fe..ea9b101e1 100644 --- a/framework/reactioncommerce/api/checkout/index.ts +++ b/framework/reactioncommerce/api/checkout/index.ts @@ -1,50 +1 @@ -import isAllowedMethod from '../utils/is-allowed-method' -import createApiHandler, { - ReactionCommerceApiHandler, -} from '../utils/create-api-handler' - -import { - REACTION_ANONYMOUS_CART_TOKEN_COOKIE, - SHOPIFY_CHECKOUT_URL_COOKIE, - REACTION_CUSTOMER_TOKEN_COOKIE, -} from '../../const' - -import { getConfig } from '..' -import associateCustomerWithCheckoutMutation from '../../utils/mutations/associate-customer-with-checkout' - -const METHODS = ['GET'] - -const checkoutApi: ReactionCommerceApiHandler = async ( - req, - res, - config -) => { - if (!isAllowedMethod(req, res, METHODS)) return - - config = getConfig() - - const { cookies } = req - const checkoutUrl = cookies[SHOPIFY_CHECKOUT_URL_COOKIE] - const customerCookie = cookies[REACTION_CUSTOMER_TOKEN_COOKIE] - - if (customerCookie) { - try { - await config.fetch(associateCustomerWithCheckoutMutation, { - variables: { - checkoutId: cookies[REACTION_ANONYMOUS_CART_TOKEN_COOKIE], - customerAccessToken: cookies[REACTION_CUSTOMER_TOKEN_COOKIE], - }, - }) - } catch (error) { - console.error(error) - } - } - - if (checkoutUrl) { - res.redirect(checkoutUrl) - } else { - res.redirect('/cart') - } -} - -export default createApiHandler(checkoutApi, {}, {}) +export default function () {} diff --git a/framework/reactioncommerce/cart/utils/checkout-create.ts b/framework/reactioncommerce/cart/utils/create-cart.ts similarity index 66% rename from framework/reactioncommerce/cart/utils/checkout-create.ts rename to framework/reactioncommerce/cart/utils/create-cart.ts index af031445d..37b3c9f84 100644 --- a/framework/reactioncommerce/cart/utils/checkout-create.ts +++ b/framework/reactioncommerce/cart/utils/create-cart.ts @@ -3,13 +3,12 @@ import { SHOPIFY_CHECKOUT_URL_COOKIE, REACTION_COOKIE_EXPIRE, } from '../../const' - -import checkoutCreateMutation from '../../utils/mutations/checkout-create' +import createCartMutation from '../../utils/mutations/create-cart' import Cookies from 'js-cookie' -export const checkoutCreate = async (fetch: any) => { +export const createCart = async (fetch: any) => { const data = await fetch({ - query: checkoutCreateMutation, + query: createCartMutation, variables: { input: { shopId, @@ -25,10 +24,9 @@ export const checkoutCreate = async (fetch: any) => { expires: REACTION_COOKIE_EXPIRE, } Cookies.set(REACTION_ANONYMOUS_CART_TOKEN_COOKIE, checkoutId, options) - Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout?.webUrl, options) } return checkout } -export default checkoutCreate +export default createCart diff --git a/framework/reactioncommerce/cart/utils/index.ts b/framework/reactioncommerce/cart/utils/index.ts index 20d04955d..08ce71ec6 100644 --- a/framework/reactioncommerce/cart/utils/index.ts +++ b/framework/reactioncommerce/cart/utils/index.ts @@ -1,2 +1,2 @@ export { default as checkoutToCart } from './checkout-to-cart' -export { default as checkoutCreate } from './checkout-create' +export { default as checkoutCreate } from './create-cart' diff --git a/framework/reactioncommerce/const.ts b/framework/reactioncommerce/const.ts index c0faf6752..297d262fa 100644 --- a/framework/reactioncommerce/const.ts +++ b/framework/reactioncommerce/const.ts @@ -5,8 +5,6 @@ export const REACTION_CART_ID_COOKIE = 'reaction_cartId' export const REACTION_EMPTY_DUMMY_CART_ID = 'DUMMY_EMPTY_CART_ID' -export const SHOPIFY_CHECKOUT_URL_COOKIE = 'shopify_checkoutUrl' - export const REACTION_CUSTOMER_TOKEN_COOKIE = 'reaction_customerToken' export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN diff --git a/framework/reactioncommerce/utils/mutations/checkout-create.ts b/framework/reactioncommerce/utils/mutations/create-cart.ts similarity index 86% rename from framework/reactioncommerce/utils/mutations/checkout-create.ts rename to framework/reactioncommerce/utils/mutations/create-cart.ts index e40d46af2..0ae2a91a8 100644 --- a/framework/reactioncommerce/utils/mutations/checkout-create.ts +++ b/framework/reactioncommerce/utils/mutations/create-cart.ts @@ -4,7 +4,7 @@ import { minOrderQuantityFailureDetailsFragment, } from '@framework/utils/queries/get-checkout-query' -const checkoutCreateMutation = /* GraphQL */ ` +const createCartMutation = /* GraphQL */ ` mutation createCartMutation($input: CreateCartInput!) { createCart(input: $input) { cart { @@ -21,4 +21,4 @@ const checkoutCreateMutation = /* GraphQL */ ` } } ` -export default checkoutCreateMutation +export default createCartMutation diff --git a/framework/reactioncommerce/utils/mutations/index.ts b/framework/reactioncommerce/utils/mutations/index.ts index b79231032..f27a0d976 100644 --- a/framework/reactioncommerce/utils/mutations/index.ts +++ b/framework/reactioncommerce/utils/mutations/index.ts @@ -1,6 +1,6 @@ export { default as addCartItemsMutation } from './add-cart-items' export { default as createUserMutation } from './create-user' -export { default as checkoutCreateMutation } from './checkout-create' +export { default as createCartMutation } from './create-cart' export { default as authenticateMutation } from './authenticate' export { default as logoutMutation } from './logout' export { default as removeCartItemsMutation } from './remove-cart-items'