- caaloghi, categorie
This commit is contained in:
@@ -172,12 +172,6 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getProductById: (state: IProductsState) => (id: string): IProduct => {
|
||||
const prod = state.products.find((prod: IProduct) => prod._id === id)
|
||||
return prod ? prod : getRecordProductEmpty()
|
||||
},
|
||||
|
||||
getProductByCode: (state: IProductsState) => (code: string): IProduct => {
|
||||
if (!code) {
|
||||
return getRecordProductEmpty()
|
||||
@@ -410,6 +404,19 @@ export const useProducts = defineStore('Products', {
|
||||
this.products = [...arrprod]
|
||||
},*/
|
||||
|
||||
async getProductById (id: string): Promise<IProduct> {
|
||||
let prod = null
|
||||
if (!this.products) {
|
||||
// Se non lo carico all'avvio, allora fai la chiamata al server
|
||||
prod = await this.loadProductById(id)
|
||||
} else {
|
||||
prod = this.products.find((prod: IProduct) => prod._id === id)
|
||||
}
|
||||
|
||||
return prod ? prod : getRecordProductEmpty()
|
||||
},
|
||||
|
||||
|
||||
async loadProducts() {
|
||||
|
||||
const userStore = useUserStore()
|
||||
@@ -882,7 +889,7 @@ export const useProducts = defineStore('Products', {
|
||||
return ris
|
||||
},
|
||||
async addtoCartBase({ $q, t, id, order, addqty }: { $q: any, t: any, id: string, order: IOrder, addqty: boolean }) {
|
||||
let product = this.getProductById(id)
|
||||
let product = await this.getProductById(id)
|
||||
|
||||
return await this.addToCart({ product, order, addqty })
|
||||
.then((ris) => {
|
||||
|
||||
Reference in New Issue
Block a user