Implemented promocode application feature in the cart, allowing users to select and apply discounts during checkout. Updated GraphQL mutation, cart logic, and UI to support this functionality. - Enhanced `cart.vue` with a new promocode selection section, including dropdown and styling. - Modified `buyOrder` mutation to accept `promocodeUuid` and `forceBalance` parameters. - Updated translations (`en-gb.json` and `ru-ru.json`) to include promocode-related strings. Improves user experience by enabling discount application directly in the cart. No breaking changes.
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { BUY_CART } from '@graphql/mutations/cart';
|
|
import type { IBuyOrderResponse } from '@types';
|
|
|
|
export function useOrderBuy() {
|
|
const { t } = useI18n();
|
|
const { $notify } = useNuxtApp();
|
|
const cartStore = useCartStore();
|
|
|
|
const orderUuid = computed(() => cartStore.currentOrder?.uuid);
|
|
|
|
const { mutate, loading, error } = useMutation<IBuyOrderResponse>(BUY_CART);
|
|
|
|
async function buyOrder(promocodeUuid?: string) {
|
|
const result = await mutate({
|
|
orderUuid: orderUuid.value,
|
|
forcePayment: true,
|
|
forceBalance: false,
|
|
promocodeUuid: promocodeUuid
|
|
});
|
|
|
|
if (result?.data?.buyOrder?.transaction?.process?.url) {
|
|
window.location.href = result.data.buyOrder.transaction.process.url;
|
|
} else {
|
|
console.log(result?.data);
|
|
}
|
|
}
|
|
|
|
watch(error, (err) => {
|
|
if (!err) return;
|
|
console.error('useOrderBuy error:', err);
|
|
let message = t('popup.errors.defaultError');
|
|
if (isGraphQLError(err)) {
|
|
message = err.graphQLErrors?.[0]?.message || message;
|
|
} else {
|
|
message = err.message;
|
|
}
|
|
$notify({
|
|
message,
|
|
type: 'error',
|
|
title: t('popup.errors.main'),
|
|
});
|
|
});
|
|
|
|
return {
|
|
buyOrder,
|
|
loading,
|
|
};
|
|
}
|