fix: translate
This commit is contained in:
@@ -23,7 +23,8 @@ export interface ProductResponse {
|
||||
}
|
||||
|
||||
export const useProductStore = defineStore('product', () => {
|
||||
const productDescription = ref()
|
||||
const productDescription = ref<ProductDescription | null>(null)
|
||||
const defaultProductDescription = ref<ProductDescription | null>(null)
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
@@ -36,9 +37,7 @@ export const useProductStore = defineStore('product', () => {
|
||||
const response = await useFetchJson<ProductDescription>(
|
||||
`/api/v1/restricted/product-translation/get-product-description?productID=${productID}&productLangID=${langId}`
|
||||
)
|
||||
console.log(response, 'dfsfsdf');
|
||||
productDescription.value = response.items
|
||||
|
||||
} catch (e: unknown) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load product description'
|
||||
} finally {
|
||||
@@ -46,21 +45,31 @@ export const useProductStore = defineStore('product', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveProductDescription(productID?: number) {
|
||||
async function getDefaultProductDescription(langId: number, productID: number) {
|
||||
try {
|
||||
const response = await useFetchJson<ProductDescription>(
|
||||
`/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=1&productLangID=1`,
|
||||
`/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
|
||||
})
|
||||
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
|
||||
@@ -91,10 +100,12 @@ export const useProductStore = defineStore('product', () => {
|
||||
|
||||
return {
|
||||
productDescription,
|
||||
defaultProductDescription,
|
||||
currentProduct,
|
||||
loading,
|
||||
error,
|
||||
getProductDescription,
|
||||
getDefaultProductDescription,
|
||||
clearCurrentProduct,
|
||||
saveProductDescription,
|
||||
translateProductDescription,
|
||||
|
||||
Reference in New Issue
Block a user