additions to product page
This commit is contained in:
@ -151,6 +151,28 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
}
|
||||
};
|
||||
|
||||
function navigateToShop() {
|
||||
navigateToItem(menuItems.value?.items.find(item => item.page_name === 'shop'))
|
||||
}
|
||||
|
||||
// function redirectToPage(link_rewrite: string) {
|
||||
// const page = menuItems.value?.items.find(
|
||||
// (item) => item.link_rewrite === link_rewrite
|
||||
// );
|
||||
|
||||
// if (!page?.id_page || !page?.link_rewrite) {
|
||||
// console.warn(`Page not found or missing data for name: ${link_rewrite}`);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// router.push({
|
||||
// params: {
|
||||
// id: page?.id_page,
|
||||
// slug: page?.link_rewrite,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
const getFirstImage = () => {
|
||||
const req = useRequestEvent();
|
||||
const url = useRequestURL();
|
||||
@ -210,24 +232,6 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
};
|
||||
});
|
||||
|
||||
function redirectToPage(link_rewrite: string) {
|
||||
const page = menuItems.value?.items.find(
|
||||
(item) => item.link_rewrite === link_rewrite
|
||||
);
|
||||
|
||||
if (!page?.id_page || !page?.link_rewrite) {
|
||||
console.warn(`Page not found or missing data for name: ${link_rewrite}`);
|
||||
return;
|
||||
}
|
||||
|
||||
router.push({
|
||||
params: {
|
||||
id: page?.id_page,
|
||||
slug: page?.link_rewrite,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
watch($i18n.locale, async () => {
|
||||
await loadMenu();
|
||||
await loadFooter();
|
||||
@ -247,13 +251,14 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
selectedCountry,
|
||||
selectedCurrency,
|
||||
selectedPhoneCountry,
|
||||
defaultMenu,
|
||||
headMeta,
|
||||
navigateToShop,
|
||||
loadMenu,
|
||||
loadFooter,
|
||||
getCountryList,
|
||||
navigateToItem,
|
||||
redirectToPage,
|
||||
getCurrencies,
|
||||
defaultMenu,
|
||||
headMeta,
|
||||
// redirectToPage,
|
||||
getCurrencies
|
||||
};
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
export const useProductStore = defineStore("productStore", () => {
|
||||
const productList = ref();
|
||||
const modules = ref();
|
||||
|
||||
async function getList(count: number, categoryId = 1) {
|
||||
try {
|
||||
@ -23,8 +24,82 @@ export const useProductStore = defineStore("productStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function getModules() {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/module/e_shop`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
modules.value = data.children.find(
|
||||
(item: { id: number; name: string }) =>
|
||||
item.name === "currency_rates_bar"
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function addToCart(product) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/user/cart/item/add/${product.id}/1`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
console.log(data);
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
const cart = ref();
|
||||
async function getCart() {
|
||||
try {
|
||||
const res = await fetch(`http://127.0.0.1:4000/api/public/user/cart`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
console.log(data);
|
||||
|
||||
cart.value = data;
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
productList,
|
||||
modules,
|
||||
getList,
|
||||
getModules,
|
||||
addToCart,
|
||||
getCart,
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user