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

@@ -3,7 +3,7 @@ import {ofetch} from "ofetch";
const BASE_URL = '/';
export const apiFetch = ofetch.create({
onRequest({ request, options }) {
onRequest({request, options}) {
const initData = window.Telegram?.WebApp?.initData
if (initData) {
@@ -15,7 +15,7 @@ export const apiFetch = ofetch.create({
},
});
export default async function (action, query = null, json = null) {
async function ftch(action, query = null, json = null) {
const options = {
method: json ? 'POST' : 'GET',
}
@@ -23,4 +23,39 @@ export default async function (action, query = null, json = null) {
if (json) options.body = json;
return await apiFetch(`${BASE_URL}index.php?route=extension/tgshop/handle&api_action=${action}`, options);
};
}
export async function storeOrder(data) {
return await apiFetch(`${BASE_URL}index.php?route=extension/tgshop/handle&api_action=storeOrder`, {
method: 'POST',
body: data,
});
}
export async function getCart() {
return await ftch('getCart');
}
export async function addToCart(data) {
return await apiFetch(`${BASE_URL}index.php?route=checkout/cart/add`, {
method: 'POST',
body: data,
});
}
export async function cartRemoveItem(data) {
return await apiFetch(`${BASE_URL}index.php?route=checkout/cart/remove`, {
method: 'POST',
body: data,
});
}
export async function cartEditItem(data) {
return await apiFetch(`${BASE_URL}index.php?route=checkout/cart/edit`, {
redirect: 'manual',
method: 'POST',
body: data,
});
}
export default ftch;