feat: create new order

This commit is contained in:
Nikita Kiselev
2025-07-31 23:48:11 +03:00
parent eb1f1dc9c1
commit c057f4be76
24 changed files with 891 additions and 319 deletions

View File

@@ -1,6 +1,6 @@
import {defineStore} from "pinia";
import {isNotEmpty} from "@/helpers.js";
import {apiFetch} from "@/utils/ftch.js";
import {addToCart, cartEditItem, cartRemoveItem, getCart} from "@/utils/ftch.js";
export const useCartStore = defineStore('cart', {
state: () => ({
@@ -26,7 +26,7 @@ export const useCartStore = defineStore('cart', {
async getProducts() {
try {
this.isLoading = true;
const data = await apiFetch('/index.php?route=extension/tgshop/handle/cart');
const {data} = await getCart();
this.items = data.products;
this.productsCount = data.total_products_count;
this.totals = data.totals;
@@ -62,10 +62,7 @@ export const useCartStore = defineStore('cart', {
}
})
const response = await apiFetch('/index.php?route=checkout/cart/add', {
method: 'POST',
body: formData,
});
const response = await addToCart(formData);
if (response.error) {
throw new Error(JSON.stringify(response.error));
@@ -85,10 +82,7 @@ export const useCartStore = defineStore('cart', {
this.isLoading = true;
const formData = new FormData();
formData.append('key', rowId);
await apiFetch('/index.php?route=checkout/cart/remove', {
method: 'POST',
body: formData,
});
await cartRemoveItem(formData);
await this.getProducts();
} catch (error) {
console.error(error);
@@ -102,11 +96,7 @@ export const useCartStore = defineStore('cart', {
this.isLoading = true;
const formData = new FormData();
formData.append(`quantity[${cartId}]`, quantity);
await apiFetch('/index.php?route=checkout/cart/edit', {
redirect: 'manual',
method: 'POST',
body: formData,
});
await cartEditItem(formData);
await this.getProducts();
} catch (error) {
console.log(error);
@@ -115,4 +105,4 @@ export const useCartStore = defineStore('cart', {
}
},
},
});
});