diff --git a/bo/src/stores/product.ts b/bo/src/stores/product.ts index f4da339..de09a7a 100644 --- a/bo/src/stores/product.ts +++ b/bo/src/stores/product.ts @@ -27,13 +27,12 @@ export const useProductStore = defineStore('product', () => { const loading = ref(false) const error = ref(null) - // Fetch all products - async function getProductDescription() { + async function getProductDescription(langId: number = 1) { loading.value = true error.value = null try { - const response = await useFetchJson('/api/v1/restricted/product-description/get-product-description?productID=51&productShopID=1&productLangID=1') + const response = await useFetchJson(`/api/v1/restricted/product-description/get-product-description?productID=51&productShopID=1&productLangID=${langId}`) productDescription.value = response } catch (e: any) { error.value = e?.message || 'Failed to load product description' @@ -43,60 +42,20 @@ export const useProductStore = defineStore('product', () => { } } - async function getProductDescriptionTranslations() { - loading.value = true - error.value = null - - try { - const response = await useFetchJson('api/v1/restricted/product-description/translate-product-description?productID=51&productShopID=1&productFromLangID=1&productToLangID=2') - productDescription.value = response - } catch (e: any) { - error.value = e?.message || 'Failed to load product description' - console.error('Failed to fetch product description:', e) - } finally { - loading.value = false - } - } - - // Fetch single product by ID - async function fetchProductById(id: number) { - loading.value = true - error.value = null - currentProduct.value = null - - try { - const data = await useFetchJson<{ items: Product }>(`/api/v1/restricted/product-description?id=${id}`) - - const response = (data as any).items || data - currentProduct.value = response.items?.[0] || response - } catch (e: any) { - error.value = e?.message || 'Failed to load product' - console.error('Failed to fetch product:', e) - } finally { - loading.value = false - } - } - - - async function saveProductDescription(description: string) { + async function saveProductDescription() { try { const data = await useFetchJson( `/api/v1/restricted/product-description/save-product-description?productID=1&productShopID=1&productLangID=1`, { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - description: description, - description_short: "

Test short

", - meta_description: "This is a test", - meta_title: "...", - name: "...", - available_now: "Test", - available_later: "...", - usage: "

test

" - }) + body: JSON.stringify( + { + description: productDescription.value.description, + description_short: productDescription.value.description_short, + meta_description: productDescription.value.meta_description, + available_now: productDescription.value.available_now, + usage: productDescription.value.usage + }) } ) return data @@ -105,7 +64,22 @@ export const useProductStore = defineStore('product', () => { } } - // Clear current product + async function translateProductDescription(fromLangId: number, toLangId: number) { + loading.value = true + error.value = null + + try { + const response = await useFetchJson(`/api/v1/restricted/product-description/translate-product-description?productID=51&productShopID=1&productFromLangID=${fromLangId}&productToLangID=${toLangId}&model=OpenAI`) + productDescription.value = response + return response + } catch (e: any) { + error.value = e?.message || 'Failed to translate product description' + console.error('Failed to translate product description:', e) + } finally { + loading.value = false + } + } + function clearCurrentProduct() { currentProduct.value = null } @@ -116,9 +90,8 @@ export const useProductStore = defineStore('product', () => { loading, error, getProductDescription, - fetchProductById, clearCurrentProduct, saveProductDescription, - getProductDescriptionTranslations + translateProductDescription } }) diff --git a/bo/src/views/customer/ProductDetailView.vue b/bo/src/views/customer/ProductDetailView.vue index adefb9a..f1a98ec 100644 --- a/bo/src/views/customer/ProductDetailView.vue +++ b/bo/src/views/customer/ProductDetailView.vue @@ -1,24 +1,45 @@ diff --git a/bo/src/views/customer/ProductsView.vue b/bo/src/views/customer/ProductsView.vue index 7ea7c9f..d20188d 100644 --- a/bo/src/views/customer/ProductsView.vue +++ b/bo/src/views/customer/ProductsView.vue @@ -155,7 +155,9 @@ function clearFilters() {