From 67ed55d11401eeb60cf302b20e55df24b0277f58 Mon Sep 17 00:00:00 2001 From: cond0r Date: Thu, 4 Feb 2021 15:35:53 +0200 Subject: [PATCH] Update index.ts --- framework/shopify/api/checkout/index.ts | 100 +----------------------- 1 file changed, 1 insertion(+), 99 deletions(-) diff --git a/framework/shopify/api/checkout/index.ts b/framework/shopify/api/checkout/index.ts index 26b8299a9..0b35324d8 100644 --- a/framework/shopify/api/checkout/index.ts +++ b/framework/shopify/api/checkout/index.ts @@ -1,103 +1,5 @@ -import { CommerceAPIFetchOptions } from '@commerce/api' -import { - CheckoutCreateInput, - CheckoutCreatePayload, - Maybe, -} from '@framework/schema' -import { getProductQuery } from 'framework/bigcommerce/product/get-product' -import Cookies from 'js-cookie' -import { getConfig, ShopifyConfig } from '..' - -const createCheckoutMutation = ` -mutation($input) { - checkoutCreate(input: $input) { - checkout { - id - webUrl - lineItems(first: 100) { - edges { - node { - title - quantity - } - } - } - } - } -} -` - -const getCheckoutQuery = ` -query { - shop { - name - currencyCode - checkout { - id - webUrl - lineItems(first: 100) { - edges { - node { - title - quantity - } - } - } - } - } -} -` - -const createCheckout = async (fetcher: any, input: CheckoutCreateInput) => { - return await fetcher(createCheckoutMutation, { - variables: { - input, - }, - }) -} - const getCheckout = async (req: any, res: any, config: any): Promise => { - console.log(config) - - return - config = getConfig(config) - - const { data: shop } = await config.fetch(getProductQuery) - - const checkout = shop?.checkout - const completedAt = checkout.completedAt - - const checkoutId = Cookies.get('nextjs-commerce-shopify-token') - - const checkoutCreateInput = { - presentmentCurrencyCode: shop?.currencyCode, - } - - // we could have a cart id stored in session storage - // user could be refreshing or navigating back and forthlet checkoutResource - let checkoutCreatePayload: Maybe - - if (checkoutId) { - checkoutCreatePayload = await createCheckout( - config.fetch, - checkoutCreateInput - ) - const existingCheckout = checkoutCreatePayload?.checkout - const completedAt = existingCheckout?.completedAt - if (completedAt) { - checkoutCreatePayload = await createCheckout( - config.fetch, - checkoutCreateInput - ) - } - } else { - checkoutCreatePayload = await createCheckout( - config.fetch, - checkoutCreateInput - ) - } - - console.log(checkout) + res.end() } export default getCheckout