Skip to content

Commit

Permalink
fix: different currencies cart merging issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Orlov committed Dec 19, 2024
1 parent 562ad95 commit 0ce8ae2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export function useChangeCartCurrencyMutation() {
variables: {
command: {
storeId,
currencyCode,
cultureName,
currencyCode,
},
},
});
Expand Down
13 changes: 13 additions & 0 deletions client-app/core/api/graphql/cart/mutations/clearCart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -12,6 +13,18 @@ export function useClearCartMutation(cart?: MaybeRef<CartIdFragment | undefined>
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<CartType> {
const { mutate } = useClearCartMutation({ id: cartId });
Expand Down
13 changes: 12 additions & 1 deletion client-app/shared/account/composables/useSignMeIn.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 () => {
Expand All @@ -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) {
Expand Down

0 comments on commit 0ce8ae2

Please sign in to comment.