Aggiornamento modifiche preOrdini
This commit is contained in:
@@ -30,6 +30,17 @@ export const useProducts = defineStore('Products', {
|
||||
const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id)
|
||||
if (indelem >= 0) {
|
||||
state.products[indelem] = { ...res.data.product }
|
||||
|
||||
/*if (!res.data.orders) {
|
||||
// aggiorna anche tutti i product negli ordini !
|
||||
let ordcart: IOrderCart
|
||||
for (ordcart of state.orders) {
|
||||
for (const item of ordcart.items!) {
|
||||
if (item.order.idProduct === res.data.product.idProduct)
|
||||
item.order.product = res.data.product
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
if (res && res.data.orders) {
|
||||
@@ -44,7 +55,10 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
getProduct: (state: IProductsState) => (code: string): IProduct => {
|
||||
const prod = state.products.find((prod: IProduct) => prod.code === code)
|
||||
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0 }
|
||||
return prod ? prod : {
|
||||
active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0,
|
||||
stockQty: 0, bookableQty: 0
|
||||
}
|
||||
},
|
||||
|
||||
getCart: (state: IProductsState) => (): ICart => {
|
||||
@@ -115,7 +129,7 @@ export const useProducts = defineStore('Products', {
|
||||
for (const item of myord.items) {
|
||||
if (item.order) {
|
||||
if (item.order.idProduct === idproduct) {
|
||||
totalQuantity += item.order.quantity || 0;
|
||||
totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +160,7 @@ export const useProducts = defineStore('Products', {
|
||||
return []
|
||||
},
|
||||
|
||||
updateQuantityAvailable: (state: IProductsState) => (id: string): any => {
|
||||
/* updateQuantityAvailable: (state: IProductsState) => (id: string): any => {
|
||||
|
||||
const indelem = state.products.findIndex((prod: IProduct) => prod._id === id)
|
||||
if (indelem >= 0) {
|
||||
@@ -154,9 +168,14 @@ export const useProducts = defineStore('Products', {
|
||||
if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) {
|
||||
state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa!
|
||||
}
|
||||
state.products[indelem].bookableAvailableQty = state.products[indelem].bookableQty
|
||||
if (state.products[indelem].QuantitaPrenotateInAttesa! > 0) {
|
||||
state.products[indelem].bookableAvailableQty! -= state.products[indelem].QuantitaPrenotateInAttesa!
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
},*/
|
||||
|
||||
getRecordEmpty: (state: IProductsState) => (): IProduct => {
|
||||
|
||||
const tomorrow = tools.getDateNow()
|
||||
@@ -182,9 +201,12 @@ export const useProducts = defineStore('Products', {
|
||||
color: '',
|
||||
size: '',
|
||||
quantityAvailable: 0,
|
||||
bookableAvailableQty: 0,
|
||||
stockQty: 0,
|
||||
bookableQty: 0,
|
||||
canBeShipped: false,
|
||||
QuantitaOrdinateInAttesa: 0,
|
||||
QuantitaPrenotateInAttesa: 0,
|
||||
canBeBuyOnline: false,
|
||||
weight: 0,
|
||||
unit: 0,
|
||||
@@ -218,6 +240,7 @@ export const useProducts = defineStore('Products', {
|
||||
weight: product.weight,
|
||||
|
||||
quantity: order.quantity,
|
||||
quantitypreordered: order.quantitypreordered,
|
||||
idStorehouse: order.idStorehouse,
|
||||
idScontisticas: product.idScontisticas,
|
||||
}
|
||||
@@ -388,12 +411,13 @@ export const useProducts = defineStore('Products', {
|
||||
const ordcart = this.getOrderProductInCart(product._id)
|
||||
if (ordcart) {
|
||||
|
||||
if (!addqty && ordcart.quantity === 1) {
|
||||
if (!addqty && ((ordcart.quantity + ordcart.quantitypreordered) === 1)) {
|
||||
// sto per rimuovere l'ultimo pezzo, quindi cancello direttamente
|
||||
const risrem = await this.removeFromCart({ order: ordcart })
|
||||
|
||||
if (risrem) {
|
||||
order.quantity = 0
|
||||
order.quantitypreordered = 0
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@@ -406,14 +430,22 @@ export const useProducts = defineStore('Products', {
|
||||
order: ordcart,
|
||||
}).then((res: any) => {
|
||||
if (res && res.risult) {
|
||||
order.quantity = res.qty
|
||||
order.quantity = res.myord.quantity
|
||||
order.quantitypreordered = res.myord.quantitypreordered
|
||||
}
|
||||
return res;
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (order.quantity === 0)
|
||||
if (this.isQtyAvailableByProduct(product)) {
|
||||
order.quantitypreordered = 0
|
||||
order.quantity = 1
|
||||
} else {
|
||||
if (this.isInPreorderByProduct(product)) {
|
||||
order.quantity = 0
|
||||
order.quantitypreordered = 1
|
||||
}
|
||||
}
|
||||
|
||||
neworder = this.createOrderByProduct(product, order)
|
||||
}
|
||||
@@ -434,7 +466,7 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return { risult: !!res, qty: order.quantity }
|
||||
return { risult: !!res }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addToCart', error)
|
||||
@@ -463,7 +495,7 @@ export const useProducts = defineStore('Products', {
|
||||
.then((res) => {
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return { risult: !!res, qty: res.data.qty }
|
||||
return { risult: !!res, myord: res.data.myord }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addSubQtyToItem', error)
|
||||
@@ -562,6 +594,47 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
getQuantityByOrder(order: IOrder): string {
|
||||
let mystr = '';
|
||||
if (order.quantity > 0) {
|
||||
mystr += order.quantity
|
||||
}
|
||||
if (order.quantitypreordered > 0) {
|
||||
mystr += ' Prenotata :' + order.quantitypreordered
|
||||
}
|
||||
return mystr
|
||||
},
|
||||
|
||||
isQtyAvailableByProduct(product: IProduct): boolean {
|
||||
if (product) {
|
||||
return (product.quantityAvailable! > 0)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isInPreorderByProduct(product: IProduct): boolean {
|
||||
if (product) {
|
||||
return (product.bookableAvailableQty! > 0)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isQtyAvailableByOrder(order: IOrder): boolean {
|
||||
if (order && order.product) {
|
||||
return this.isQtyAvailableByProduct(order.product)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isInPreorderByOrder(order: IOrder): boolean {
|
||||
if (order && order.product) {
|
||||
return this.isInPreorderByProduct(order.product)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user