saleor: attach checkout to customer

This commit is contained in:
Zaiste 2021-05-14 11:53:27 +02:00
parent 96f79e348c
commit 3e72dfcb6e
No known key found for this signature in database
GPG Key ID: 15DF7EBC7F2FFE35
5 changed files with 32 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import {
MutationTokenCreateArgs,
} from '../schema'
import useLogin, { UseLogin } from '@commerce/auth/use-login'
import { setCSRFToken, setToken, throwUserErrors } from '../utils'
import { setCSRFToken, setToken, throwUserErrors, checkoutAttach, getCheckoutId } from '../utils'
export default useLogin as UseLogin<typeof handler>
@ -40,6 +40,14 @@ export const handler: MutationHook<null, {}, MutationTokenCreateArgs> = {
if (token && csrfToken) {
setToken(token)
setCSRFToken(csrfToken)
const { checkoutId } = getCheckoutId();
checkoutAttach(fetch, {
variables: { checkoutId },
headers: {
Authorization: `JWT ${token}`
}
})
}
return null

View File

@ -0,0 +1,16 @@
import * as mutation from './mutations'
import { CheckoutCustomerAttach } from '../schema'
export const checkoutAttach = async (
fetch: any,
{ variables, headers }: any,
): Promise<CheckoutCustomerAttach> => {
const data = await fetch({
query: mutation.AttachCheckout,
variables,
headers
})
return data;
}

View File

@ -5,10 +5,14 @@ export { default as getSearchVariables } from './get-search-variables'
export { default as getVendors } from './get-vendors'
export { default as getCategories } from './get-categories'
export { default as getCheckoutId } from './get-checkout-id'
export { default as checkoutCreate } from './checkout-create'
export { checkoutAttach } from './checkout-attach';
export { default as checkoutToCart } from './checkout-to-cart'
export { default as handleLogin, handleAutomaticLogin } from './handle-login'
export { default as throwUserErrors } from './throw-user-errors'
export * from './queries'
export * from './mutations'
export * from './normalize'

View File

@ -1,5 +1,5 @@
export const checkoutCustomerAttach = /* GraphQl */ `
mutation associateCustomerWithCheckout($checkoutId: ID!) {
export const AttachCheckout = /* GraphQl */ `
mutation AttachCheckout($checkoutId: ID!) {
checkoutCustomerAttach(checkoutId: $checkoutId) {
errors {
message

View File

@ -5,3 +5,4 @@ export { checkoutLineUpdate } from './checkout-line-item-update'
export { checkoutLineDelete } from './checkout-line-item-remove'
export { sessionCreate } from './customer-access-token-create'
export { sessionDestroy } from './customer-access-token-delete'
export { AttachCheckout } from './attach-checkout'