fix: product description
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { useFetchJson } from '@/composable/useFetchJson'
|
||||
|
||||
export interface Product {
|
||||
@@ -22,31 +22,26 @@ export interface ProductResponse {
|
||||
}
|
||||
|
||||
export const useProductStore = defineStore('product', () => {
|
||||
const products = ref<Product[]>([])
|
||||
const productDescription = ref()
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
// Fetch all products
|
||||
async function fetchProducts() {
|
||||
async function getProductDescription() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
const data = await useFetchJson<ProductResponse>('/api/v1/restricted/product-description', {
|
||||
method: 'GET',
|
||||
})
|
||||
console.log(data)
|
||||
const response = (data as any).items || data
|
||||
products.value = response.items || response || []
|
||||
const response = await useFetchJson('/api/v1/restricted/product-description/get-product-description?productID=51&productShopID=1&productLangID=1')
|
||||
productDescription.value = response
|
||||
} catch (e: any) {
|
||||
error.value = e?.message || 'Failed to load products'
|
||||
console.error('Failed to fetch products:', e)
|
||||
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
|
||||
@@ -74,11 +69,11 @@ console.log(data)
|
||||
}
|
||||
|
||||
return {
|
||||
products,
|
||||
productDescription,
|
||||
currentProduct,
|
||||
loading,
|
||||
error,
|
||||
fetchProducts,
|
||||
getProductDescription,
|
||||
fetchProductById,
|
||||
clearCurrentProduct,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user