From 0ce8ae2f4b9cc5bcb43c89b4c65038f9fa47e2af Mon Sep 17 00:00:00 2001 From: Andrew Orlov Date: Thu, 19 Dec 2024 16:52:35 +0200 Subject: [PATCH] fix: different currencies cart merging issue --- .../cart/mutations/changeCartCurrency/index.ts | 2 +- .../api/graphql/cart/mutations/clearCart/index.ts | 13 +++++++++++++ .../shared/account/composables/useSignMeIn.ts | 13 ++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/client-app/core/api/graphql/cart/mutations/changeCartCurrency/index.ts b/client-app/core/api/graphql/cart/mutations/changeCartCurrency/index.ts index aed85ad0e4..f74bc80b21 100644 --- a/client-app/core/api/graphql/cart/mutations/changeCartCurrency/index.ts +++ b/client-app/core/api/graphql/cart/mutations/changeCartCurrency/index.ts @@ -8,8 +8,8 @@ export function useChangeCartCurrencyMutation() { variables: { command: { storeId, - currencyCode, cultureName, + currencyCode, }, }, }); diff --git a/client-app/core/api/graphql/cart/mutations/clearCart/index.ts b/client-app/core/api/graphql/cart/mutations/clearCart/index.ts index 7013d0f35b..e9b9bbf083 100644 --- a/client-app/core/api/graphql/cart/mutations/clearCart/index.ts +++ b/client-app/core/api/graphql/cart/mutations/clearCart/index.ts @@ -2,6 +2,7 @@ import { useApolloClient } from "@vue/apollo-composable"; import { useCartMutationVariables } from "@/core/api/graphql/cart/composables"; import { useMutation } from "@/core/api/graphql/composables"; import { ClearCartDocument } from "@/core/api/graphql/types"; +import { globals } from "@/core/globals"; import type { CartIdFragment, CartType } from "@/core/api/graphql/types"; import type { MaybeRef } from "vue"; @@ -12,6 +13,18 @@ export function useClearCartMutation(cart?: MaybeRef return result; } +export function useClearCurrencyCartMutation() { + const { storeId, cultureName } = globals; + return useMutation(ClearCartDocument, { + variables: { + command: { + storeId, + cultureName, + }, + }, + }); +} + /** @deprecated Use {@link useClearCartMutation} instead. */ export async function clearCart(cartId: string): Promise { const { mutate } = useClearCartMutation({ id: cartId }); diff --git a/client-app/shared/account/composables/useSignMeIn.ts b/client-app/shared/account/composables/useSignMeIn.ts index 46f31cfa46..4cc8c2147b 100644 --- a/client-app/shared/account/composables/useSignMeIn.ts +++ b/client-app/shared/account/composables/useSignMeIn.ts @@ -1,6 +1,11 @@ import { syncRefs, useAsyncState } from "@vueuse/core"; import { ref } from "vue"; -import { useChangeCartCurrencyMutation, useGetMeQuery, useMergeCartMutation } from "@/core/api/graphql"; +import { + useChangeCartCurrencyMutation, + useClearCurrencyCartMutation, + useGetMeQuery, + useMergeCartMutation, +} from "@/core/api/graphql"; import { useAuth } from "@/core/composables/useAuth"; import { useCurrency } from "@/core/composables/useCurrency"; import { useLanguages } from "@/core/composables/useLanguages"; @@ -20,6 +25,7 @@ export function useSignMeIn() { const { supportedCurrencies, saveCurrencyCode } = useCurrency(); const { mutate: changeCartCurrency } = useChangeCartCurrencyMutation(); const { currencyCode: currentCurencyCode } = globals; + const { mutate: clearCurrencyCart } = useClearCurrencyCartMutation(); const { isLoading: loading, execute: signIn } = useAsyncState( async () => { @@ -35,6 +41,11 @@ export function useSignMeIn() { if (me.value?.me && currencyCode) { if (cart.value?.id) { + await clearCurrencyCart({ + command: { userId: me.value.me.id, currencyCode: currentCurencyCode }, + skipQuery: false, + }); + await mergeCart({ command: { userId: me.value.me.id, secondCartId: cart.value.id } }); if (currencyCode !== currentCurencyCode) {