conflicts
This commit is contained in:
@ -13,6 +13,7 @@ import type { CartProduct } from "~/types/product";
|
||||
export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
const { $toast } = useNuxtApp();
|
||||
const menuStore = useMenuStore();
|
||||
|
||||
const selectedIso = ref(menuStore.selectedCountry);
|
||||
|
||||
const vLegal = ref(false);
|
||||
@ -196,6 +197,8 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
},
|
||||
)
|
||||
|
||||
console.log(res);
|
||||
|
||||
if (res.status === 200) {
|
||||
$toast.success('Form successfully sent', {
|
||||
autoClose: 5000,
|
||||
@ -379,7 +382,7 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
// get bank data
|
||||
const paymentMethods = ref([] as Payment[]);
|
||||
const fullAddress = ref<Address>();
|
||||
const currentPayment = ref<Payment | null>(null);
|
||||
const currentPayment = ref<Payment | null>();
|
||||
async function getBankAccount() {
|
||||
try {
|
||||
const { data } = await useMyFetch<GenericResponse<Payment[]>>(
|
||||
@ -429,9 +432,9 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function setNewAddress(index: number) {
|
||||
async function setNewAddress(indexItem: number) {
|
||||
currentPayment.value = paymentMethods.value.find(
|
||||
(item, index) => index === index
|
||||
(item, index) => indexItem === index
|
||||
);
|
||||
}
|
||||
|
||||
@ -443,12 +446,12 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
vTerms.value
|
||||
? (termsValidation.value = false)
|
||||
: (termsValidation.value = true);
|
||||
// if (vTerms.value && vLegal.value) {
|
||||
// isModalOpen.value = true;
|
||||
// }
|
||||
if (!vTerms.value && !vLegal.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await useMyFetch<GenericResponse<object>>(
|
||||
await useMyFetch<GenericResponse<object>>(
|
||||
`/api/restricted/cart/checkout/delivery`,
|
||||
{
|
||||
method: "PUT",
|
||||
@ -471,7 +474,9 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
}
|
||||
);
|
||||
|
||||
putCheckoutBankAccount();
|
||||
await putCheckoutBankAccount();
|
||||
await markOrder();
|
||||
await getUserCart();
|
||||
} catch (error) {
|
||||
console.error("uploadAddress error:", error);
|
||||
}
|
||||
@ -481,19 +486,12 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
async function putCheckoutBankAccount() {
|
||||
try {
|
||||
const res = await useMyFetch<GenericResponse<object>>(
|
||||
`restricted/cart/checkout/bank-account/${currentPayment.value?.id}`,
|
||||
`/api/restricted/cart/checkout/bank-account/${currentPayment.value?.id}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
accept_general_conditions: true,
|
||||
accept_long_purchase: true,
|
||||
address: fullAddress.value,
|
||||
delivery_option_id: currentDelivery.value.id,
|
||||
note: vNote.value,
|
||||
}),
|
||||
onErrorOccured: async (_, status) => {
|
||||
throw createError({
|
||||
statusCode: status,
|
||||
@ -507,6 +505,42 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
const modalMadeOrder = ref(false);
|
||||
async function markOrder() {
|
||||
try {
|
||||
const res = await useMyFetch<GenericResponse<object>>(
|
||||
`/api/restricted/cart/checkout/order`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: async (_, status) => {
|
||||
throw createError({
|
||||
statusCode: status,
|
||||
statusMessage: `HTTP error: ${status}`,
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (res.status === 200 || res.status === 201) {
|
||||
$toast.success("Address successfully added", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
});
|
||||
modalMadeOrder.value = true;
|
||||
} else {
|
||||
$toast.error("Failed to add address. Please try again.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
});
|
||||
}
|
||||
// window.location.href = `/golden-panel/my-purchases/${res._data?.data.id}`;
|
||||
} catch (error) {
|
||||
console.error("uploadAddress error:", error);
|
||||
}
|
||||
}
|
||||
return {
|
||||
addressesList,
|
||||
activeAddress,
|
||||
@ -547,6 +581,7 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
vNote,
|
||||
legalValidation,
|
||||
termsValidation,
|
||||
modalMadeOrder,
|
||||
|
||||
changePrefix,
|
||||
getCheckout,
|
||||
@ -562,5 +597,6 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
getBankAccount,
|
||||
getOrder,
|
||||
setNewAddress,
|
||||
sendSummaryForm,
|
||||
};
|
||||
});
|
||||
|
@ -1,16 +1,18 @@
|
||||
import { useMyFetch } from '#imports'
|
||||
import { useMyFetch } from "#imports";
|
||||
import type {
|
||||
GenericResponse,
|
||||
GenericResponseChildren,
|
||||
GenericResponseItems,
|
||||
UserCart,
|
||||
} from '~/types'
|
||||
import type { Product } from '~/types/product'
|
||||
} from "~/types";
|
||||
import type { Product } from "~/types/product";
|
||||
|
||||
export const useProductStore = defineStore('productStore', () => {
|
||||
const { $toast } = useNuxtApp()
|
||||
const productList = ref<Product[]>()
|
||||
const modules = ref()
|
||||
export const useProductStore = defineStore("productStore", () => {
|
||||
const { $toast } = useNuxtApp();
|
||||
const productList = ref<Product[]>();
|
||||
const modules = ref();
|
||||
|
||||
const checkoutStore = useCheckoutStore();
|
||||
|
||||
async function getList(count: number, categoryId = 1) {
|
||||
try {
|
||||
@ -18,22 +20,21 @@ export const useProductStore = defineStore('productStore', () => {
|
||||
`/api/public/products/category/${categoryId}?p=1&elems=${count}`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: async (_, status) => {
|
||||
// await navigateTo("/error", { replace: true });
|
||||
throw createError({
|
||||
statusCode: status,
|
||||
statusMessage: `HTTP error: ${status}`,
|
||||
})
|
||||
});
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
productList.value = data.items
|
||||
}
|
||||
catch (error) {
|
||||
console.error('getList error:', error)
|
||||
productList.value = data.items;
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,21 +44,20 @@ export const useProductStore = defineStore('productStore', () => {
|
||||
`/api/public/module/e_shop`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => {
|
||||
throw new Error(`HTTP error: ${status}`)
|
||||
throw new Error(`HTTP error: ${status}`);
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
modules.value = data.children.find(
|
||||
(item: { id: number, name: string }) =>
|
||||
item.name === 'currency_rates_bar',
|
||||
)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('getList error:', error)
|
||||
(item: { id: number; name: string }) =>
|
||||
item.name === "currency_rates_bar"
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,36 +66,34 @@ export const useProductStore = defineStore('productStore', () => {
|
||||
const res = await useMyFetch<GenericResponse<object>>(
|
||||
`/api/public/user/cart/item/add/${id}/1`,
|
||||
{
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => {
|
||||
throw new Error(`HTTP error: ${status}`)
|
||||
throw new Error(`HTTP error: ${status}`);
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
if (res.status === 200) {
|
||||
$toast.success('Item successfully added to your cart.', {
|
||||
$toast.success("Item successfully added to your cart.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
getCart()
|
||||
}
|
||||
else {
|
||||
$toast.error('Failed to add item to cart. Please try again.', {
|
||||
});
|
||||
checkoutStore.getUserCart();
|
||||
} else {
|
||||
$toast.error("Failed to add item to cart. Please try again.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
$toast.error('An unexpected error occurred while updating your cart.', {
|
||||
} catch (error) {
|
||||
$toast.error("An unexpected error occurred while updating your cart.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
console.error('incrementCartItem error:', error)
|
||||
});
|
||||
console.error("incrementCartItem error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,36 +102,34 @@ export const useProductStore = defineStore('productStore', () => {
|
||||
const res = await useMyFetch<GenericResponse<object>>(
|
||||
`/api/public/user/cart/item/subtract/${id}/1`,
|
||||
{
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => {
|
||||
throw new Error(`HTTP error: ${status}`)
|
||||
throw new Error(`HTTP error: ${status}`);
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
if (res.status === 200) {
|
||||
$toast.success('Item successfully removed from your cart.', {
|
||||
$toast.success("Item successfully removed from your cart.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
getCart()
|
||||
}
|
||||
else {
|
||||
$toast.error('Failed to removed item from cart. Please try again.', {
|
||||
});
|
||||
checkoutStore.getUserCart();
|
||||
} else {
|
||||
$toast.error("Failed to removed item from cart. Please try again.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
$toast.error('An unexpected error occurred while updating your cart.', {
|
||||
} catch (error) {
|
||||
$toast.error("An unexpected error occurred while updating your cart.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
console.error('decrementCartItem error:', error)
|
||||
});
|
||||
console.error("decrementCartItem error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,70 +138,44 @@ export const useProductStore = defineStore('productStore', () => {
|
||||
const res = await useMyFetch<GenericResponse<object>>(
|
||||
`/api/public/user/cart/item/${id}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => {
|
||||
throw new Error(`HTTP error: ${status}`)
|
||||
throw new Error(`HTTP error: ${status}`);
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
if (res.status === 200) {
|
||||
$toast.success('Item successfully removed from your cart.', {
|
||||
$toast.success("Item successfully removed from your cart.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
getCart()
|
||||
}
|
||||
else {
|
||||
$toast.error('Failed to removed item from cart. Please try again.', {
|
||||
});
|
||||
checkoutStore.getUserCart();
|
||||
} else {
|
||||
$toast.error("Failed to removed item from cart. Please try again.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
$toast.error('An unexpected error occurred while updating your cart.', {
|
||||
} catch (error) {
|
||||
$toast.error("An unexpected error occurred while updating your cart.", {
|
||||
autoClose: 5000,
|
||||
dangerouslyHTMLString: true,
|
||||
})
|
||||
console.error('deleteCartItem error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const cart = ref({} as UserCart)
|
||||
async function getCart() {
|
||||
try {
|
||||
const { data } = await useMyFetch<GenericResponse<UserCart>>(
|
||||
`/api/public/user/cart`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
onErrorOccured: (_, status) => {
|
||||
throw new Error(`HTTP error: ${status}`)
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
cart.value = data
|
||||
}
|
||||
catch (error) {
|
||||
console.error('getList error:', error)
|
||||
});
|
||||
console.error("deleteCartItem error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
productList,
|
||||
modules,
|
||||
cart,
|
||||
getList,
|
||||
getModules,
|
||||
incrementCartItem,
|
||||
decrementCartItem,
|
||||
deleteCartItem,
|
||||
getCart,
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user