Skip to content

Commit

Permalink
fix: merge cart issue on currency change
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Orlov committed Dec 24, 2024
1 parent 96df54d commit 94ce283
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
v-model="currentCurrency.code"
:value="currencyItem.code"
class="py-2.5"
@click="currentCurrency?.code === currencyItem.code ? null : saveCurrencyCode(currencyItem.code)"
@click="changeCurrency(currencyItem.code)"
>
<span :class="{ 'text-additional-50': currentCurrency?.code === currencyItem.code }" class="uppercase">
{{ currencyItem.code }}
Expand All @@ -20,7 +20,27 @@
</template>

<script setup lang="ts">
import { useChangeCartCurrencyMutation } from "@/core/api/graphql";
import { useCurrency } from "@/core/composables";
import { globals } from "@/core/globals";
import { useFullCart } from "@/shared/cart";
const { currentCurrency, supportedCurrencies, saveCurrencyCode } = useCurrency();
const { cart } = useFullCart();
const { mutate: changeCartCurrency } = useChangeCartCurrencyMutation();
const { userId } = globals;
async function changeCurrency(code: string): Promise<void> {
if (currentCurrency.value?.code !== code && cart.value) {
await changeCartCurrency({
command: {
userId,
cartId: cart.value.id,
newCurrencyCode: code,
},
});
saveCurrencyCode(code);
}
}
</script>

0 comments on commit 94ce283

Please sign in to comment.