-
-
-
-
-
-
-
- {{langOptions.find(l => l.id === modelValue)?.name}}
-
-
-
-
-
- {{ item.name }}
-
-
-
-
-
- Translate
-
-
-
-
-
-
-
- Back to Polish
-
-
+
+
+
+
+ {{availableLangs.find(x => x.id == modelValue)?.flag}}
+ {{availableLangs.find(x => x.id ==
+ modelValue)?.name}}
+
+
+
+
+ {{ item.flag }}
+ {{ item.name }}
+
+
+
+
+ Translate
+
-
- No translation available
-
-
@@ -54,7 +37,6 @@
-
@@ -63,14 +45,11 @@
Product Image
-
- {{ productName || 'Product Name' }}
+ {{ productStore.productDescription.name || 'Product Name' }}
-
-
-
+
@@ -78,7 +57,6 @@
{{ productStore.productDescription.available_now }}
-
-
+
-
- Description
+
+ Description
-
- Usage
+
+ Usage
-
-
-
-
- Edit Usage
+
+
+
+
+ Change Text
+
+
+
+ Save the edited text
+
+
+ Cancel
-
Save
-
Cancel
-
-
+
-
-
-
+
+
- Edit Description
+ class="flex items-center gap-2 m-2 cursor-pointer bg-(--accent-blue-light)! dark:bg-(--accent-blue-dark)!">
+ Change Text
+
-
- Save
+
+ Save the edited text
-
- Cancel
+ Cancel
+
+
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bo/src/stores/product.ts b/bo/src/stores/product.ts
index 9380645..27e3ad7 100644
--- a/bo/src/stores/product.ts
+++ b/bo/src/stores/product.ts
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useFetchJson } from '@/composable/useFetchJson'
import type { ProductDescription } from '@/types/product'
+import { useSettingsStore } from './settings'
export interface Product {
id: number
@@ -23,21 +24,20 @@ export interface ProductResponse {
}
export const useProductStore = defineStore('product', () => {
- const productDescription = ref(null)
- const defaultProductDescription = ref(null)
- const currentProduct = ref(null)
+
const loading = ref(false)
const error = ref(null)
+ const productDescription = ref()
- async function getProductDescription(langId = 1, productID: number) {
+ async function getProductDescription(langId: number, productID: number) {
loading.value = true
error.value = null
-
try {
const response = await useFetchJson(
`/api/v1/restricted/product-translation/get-product-description?productID=${productID}&productLangID=${langId}`
)
productDescription.value = response.items
+ console.log(productDescription, 'dfsfsdf');
} catch (e: unknown) {
error.value = e instanceof Error ? e.message : 'Failed to load product description'
} finally {
@@ -45,45 +45,12 @@ export const useProductStore = defineStore('product', () => {
}
}
- async function getDefaultProductDescription(langId: number, productID: number) {
- try {
- const response = await useFetchJson(
- `/api/v1/restricted/product-translation/get-product-description?productID=${productID}&productLangID=${langId}`
- )
- defaultProductDescription.value = response.items
- } catch (e: unknown) {
- console.error('Failed to load default product description:', e)
- }
- }
-
- async function saveProductDescription(productID?: number, langId?: number, shopId = 1) {
- const id = productID || 1
- try {
- const data = await useFetchJson(
- `/api/v1/restricted/product-description/save-product-description?productID=${id}&productShopID=${shopId}&productLangID=${langId ?? 1}`,
- {
- method: 'POST',
- 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
- } catch (e) {
- console.error(e)
- }
- }
-
- async function translateProductDescription(productID: number, fromLangId: number, toLangId: number) {
+ async function translateProductDescription(productID: number, toLangId: number, defaultLangId: number, model: string = 'OpenAI') {
loading.value = true
error.value = null
try {
- const response = await useFetchJson(`/api/v1/restricted/product-description/translate-product-description?productID=${productID}&productShopID=1&productFromLangID=${fromLangId}&productToLangID=${toLangId}&model=OpenAI`)
+ const response = await useFetchJson(`/api/v1/restricted/product-translation/translate-product-description?productID=${productID}&productFromLangID=${defaultLangId}&productToLangID=${toLangId}&model=${model}`)
productDescription.value = response.items
return response.items
} catch (e: any) {
@@ -94,20 +61,166 @@ export const useProductStore = defineStore('product', () => {
}
}
- function clearCurrentProduct() {
- currentProduct.value = null
+
+ function stripHtml(html: string) {
+ const div = document.createElement('div')
+ div.innerHTML = html
+ return div.textContent || div.innerText || ''
+ }
+
+ async function saveProductDescription(productID?: number, langId?: number) {
+ const id = productID || 1
+ const lang = langId || 1
+ try {
+ const data = await useFetchJson(
+ `/api/v1/restricted/product-translation/save-product-description?productID=${id}&productLangID=${lang}`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ name: stripHtml(productDescription.value?.name || ''),
+ description: stripHtml(productDescription.value?.description || ''),
+ description_short: stripHtml(productDescription.value?.description_short || ''),
+ meta_title: stripHtml(productDescription.value?.meta_title || ''),
+ meta_description: stripHtml(productDescription.value?.meta_description || ''),
+ available_now: stripHtml(productDescription.value?.available_now || ''),
+ available_later: stripHtml(productDescription.value?.available_later || ''),
+ usage: stripHtml(productDescription.value?.usage || '')
+ })
+ }
+ )
+ return data
+ } catch (e) {
+ console.error(e)
+ }
}
return {
productDescription,
- defaultProductDescription,
- currentProduct,
loading,
error,
- getProductDescription,
- getDefaultProductDescription,
- clearCurrentProduct,
- saveProductDescription,
translateProductDescription,
+ getProductDescription,
+ saveProductDescription
+
}
})
+
+
+
+// import { defineStore } from 'pinia'
+// import { ref } from 'vue'
+// import { useFetchJson } from '@/composable/useFetchJson'
+// import type { ProductDescription } from '@/types/product'
+// import { useSettingsStore } from './settings'
+
+// export interface Product {
+// id: number
+// image: string
+// name: string
+// code: string
+// inStock: boolean
+// priceFrom: number
+// priceTo: number
+// count: number
+// description?: string
+// howToUse?: string
+// productDetails?: string
+// }
+
+// export interface ProductResponse {
+// items: Product[]
+// items_count: number
+// }
+
+// export const useProductStore = defineStore('product', () => {
+// const productDescription = ref()
+// const currentProduct = ref(null)
+// const loading = ref(false)
+// const error = ref(null)
+
+// async function getProductDescription(langId = 1, productID: number) {
+// loading.value = true
+// error.value = null
+
+// try {
+// const response = await useFetchJson(
+// `/api/v1/restricted/product-translation/get-product-description?productID=${productID}&productLangID=${langId}`
+// )
+// productDescription.value = response.items
+// console.log(productDescription, 'dfsfsdf');
+
+// } catch (e: unknown) {
+// error.value = e instanceof Error ? e.message : 'Failed to load product description'
+// } finally {
+// loading.value = false
+// }
+// }
+// function stripHtml(html: string) {
+// const div = document.createElement('div')
+// div.innerHTML = html
+// return div.textContent || div.innerText || ''
+// }
+// async function saveProductDescription(productID?: number, langId?: number) {
+// const id = productID || 1
+// const lang = langId || 1
+// try {
+// const data = await useFetchJson(
+// `/api/v1/restricted/product-translation/save-product-description?productID=${id}&productLangID=${lang}`,
+// {
+// method: 'POST',
+// headers: {
+// 'Content-Type': 'application/json'
+// },
+// body: JSON.stringify({
+// name: stripHtml(productDescription.value?.name || ''),
+// description: stripHtml(productDescription.value?.description || ''),
+// description_short: stripHtml(productDescription.value?.description_short || ''),
+// meta_title: stripHtml(productDescription.value?.meta_title || ''),
+// meta_description: stripHtml(productDescription.value?.meta_description || ''),
+// available_now: stripHtml(productDescription.value?.available_now || ''),
+// available_later: stripHtml(productDescription.value?.available_later || ''),
+// usage: stripHtml(productDescription.value?.usage || '')
+// })
+// }
+// )
+// return data
+// } catch (e) {
+// console.error(e)
+// }
+// }
+
+// const defaultLangId = ref(1)
+// async function translateProductDescription(productID: number, fromLangId: number, defaultLangId: number, model: string = 'OpenAI') {
+// loading.value = true
+// error.value = null
+
+// try {
+// const response = await useFetchJson(`/api/v1/restricted/product-translation/translate-product-description?productID=${productID}&productFromLangID=${fromLangId}&productToLangID=${defaultLangId}&model=${model}`)
+// productDescription.value = response.items
+// return response.items
+// } 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
+// }
+
+// return {
+// productDescription,
+// currentProduct,
+// loading,
+// error,
+// getProductDescription,
+// clearCurrentProduct,
+// saveProductDescription,
+// translateProductDescription,
+// }
+// })
\ No newline at end of file
diff --git a/bo/src/stores/settings.ts b/bo/src/stores/settings.ts
index 5fff967..6231629 100644
--- a/bo/src/stores/settings.ts
+++ b/bo/src/stores/settings.ts
@@ -2,11 +2,12 @@ import { useFetchJson } from '@/composable/useFetchJson'
import type { Resp } from '@/types'
import type { Settings } from '@/types/settings'
import { defineStore } from 'pinia'
-import { ref } from 'vue'
+import { computed, ref } from 'vue'
export const useSettingsStore = defineStore('settings', () => {
const settings = ref(null)
const loaded = ref(false)
+ const shopDefaultLanguage = computed(() => settings.value?.app?.shop_default_language ?? 1)
async function getSettings(): Promise {
if (loaded.value && settings.value) return settings.value
@@ -16,5 +17,5 @@ export const useSettingsStore = defineStore('settings', () => {
return resp.items
}
- return { settings, loaded, getSettings }
+ return { settings, loaded, shopDefaultLanguage, getSettings }
})