aggiornamento...
This commit is contained in:
@@ -44,7 +44,7 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
getProduct: (state: IProductsState) => (code: string): IProduct => {
|
||||
const prod = state.products.find((prod: IProduct) => prod.code === code)
|
||||
return prod ? prod : { storehouses: [], scontisticas: [] }
|
||||
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [] }
|
||||
},
|
||||
|
||||
getCart: (state: IProductsState) => (): ICart => {
|
||||
@@ -106,17 +106,20 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => {
|
||||
let totalQuantity = 0;
|
||||
|
||||
if (state.orders) {
|
||||
const orderscart = state.orders
|
||||
if (orderscart) {
|
||||
for (const myord of orderscart) {
|
||||
myord.items?.forEach((item: IBaseOrder) => {
|
||||
if (item.order) {
|
||||
if (item.order.idProduct === idproduct) {
|
||||
totalQuantity += item.order.quantity || 0;
|
||||
if (myord.items) {
|
||||
for (const item of myord.items) {
|
||||
if (item.order) {
|
||||
if (item.order.idProduct === idproduct) {
|
||||
totalQuantity += item.order.quantity || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,6 +127,7 @@ export const useProducts = defineStore('Products', {
|
||||
},
|
||||
|
||||
getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => {
|
||||
console.log('getOrdersCartByIdProduct')
|
||||
// console.log('.cart.items', this.cart.items)
|
||||
try {
|
||||
if (state.orders) {
|
||||
@@ -133,6 +137,7 @@ export const useProducts = defineStore('Products', {
|
||||
return item.order.idProduct === idproduct
|
||||
})
|
||||
})
|
||||
console.log('Ordini ', ris)
|
||||
return ris ? ris : []
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -141,6 +146,17 @@ export const useProducts = defineStore('Products', {
|
||||
return []
|
||||
},
|
||||
|
||||
updateQuantityAvailable: (state: IProductsState) => (id: string): any => {
|
||||
|
||||
const indelem = state.products.findIndex((prod: IProduct) => prod._id === id)
|
||||
if (indelem >= 0) {
|
||||
state.products[indelem].quantityAvailable = state.products[indelem].stockQty
|
||||
if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) {
|
||||
state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa!
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
getRecordEmpty: (state: IProductsState) => (): IProduct => {
|
||||
|
||||
const tomorrow = tools.getDateNow()
|
||||
|
||||
Reference in New Issue
Block a user