fix: styles and translations.
This commit is contained in:
@@ -27,13 +27,12 @@ export const useProductStore = defineStore('product', () => {
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(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: "<p>Test short</p>",
|
||||
meta_description: "This is a test",
|
||||
meta_title: "...",
|
||||
name: "...",
|
||||
available_now: "Test",
|
||||
available_later: "...",
|
||||
usage: "<p>test</p>"
|
||||
})
|
||||
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
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user