Corretto incongruenze OrdersCart
This commit is contained in:
@@ -123,6 +123,28 @@ export const useProducts = defineStore('Products', {
|
||||
return null
|
||||
},
|
||||
|
||||
getSumQtyPreOrderInOrdersCart: (state: IProductsState) => (idproduct: string): number => {
|
||||
let totalQuantity = 0;
|
||||
|
||||
if (state.orders) {
|
||||
const orderscart = state.orders
|
||||
if (orderscart) {
|
||||
for (const myord of orderscart) {
|
||||
if (myord.items) {
|
||||
for (const item of myord.items) {
|
||||
if (item.order) {
|
||||
if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) {
|
||||
totalQuantity += (item.order.quantitypreordered) || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalQuantity
|
||||
},
|
||||
|
||||
getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => {
|
||||
let totalQuantity = 0;
|
||||
|
||||
@@ -134,7 +156,7 @@ export const useProducts = defineStore('Products', {
|
||||
for (const item of myord.items) {
|
||||
if (item.order) {
|
||||
if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) {
|
||||
totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0;
|
||||
totalQuantity += (item.order.quantity) || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,22 +205,6 @@ 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!
|
||||
}
|
||||
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()
|
||||
@@ -461,16 +467,15 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
} else {
|
||||
if (this.isQtyAvailableByProduct(product)) {
|
||||
order.quantitypreordered = 0
|
||||
order.quantity = 1
|
||||
order.quantitypreordered = 0
|
||||
} else {
|
||||
if (this.isInPreorderByProduct(product)) {
|
||||
order.quantity = 0
|
||||
order.quantitypreordered = 1
|
||||
order.quantity = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!order.idStorehouse) {
|
||||
if (product.storehouses.length === 1) {
|
||||
order.idStorehouse = product.storehouses[0]._id
|
||||
@@ -500,7 +505,7 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return { risult: !!res }
|
||||
return { risult: !!res, myord: res.data.myord }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addToCart', error)
|
||||
@@ -631,49 +636,87 @@ export const useProducts = defineStore('Products', {
|
||||
async addtoCartBase({ $q, t, code, order, addqty }: { $q: any, t: any, code: string, order: IOrder, addqty: boolean }) {
|
||||
let product = this.getProductByCode(code)
|
||||
|
||||
return this.addToCart({ product, order, addqty }).then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
return await this.addToCart({ product, order, addqty })
|
||||
.then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
|
||||
let msg = ''
|
||||
console.log('ris', ris)
|
||||
if (ris === null || ris.myord == null) {
|
||||
msg = t('ecomm.error_cart')
|
||||
tools.showNegativeNotif($q, msg)
|
||||
return
|
||||
} else {
|
||||
|
||||
let qta = ris.myord.quantity + ris.myord.quantitypreordered
|
||||
if (qta > 1 || qta === 0)
|
||||
strprod = t('ecomm.prodotti')
|
||||
|
||||
if (qta === 0) {
|
||||
let msg = ''
|
||||
console.log('ris', ris)
|
||||
if (ris && ris.myord == null) {
|
||||
msg = t('ecomm.prodotto_tolto')
|
||||
tools.showNotif($q, msg)
|
||||
return
|
||||
}
|
||||
if (ris === null || ris.myord == null) {
|
||||
msg = t('ecomm.error_cart')
|
||||
tools.showNegativeNotif($q, msg)
|
||||
return
|
||||
} else {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta })
|
||||
|
||||
let qta = ris.myord.quantity + ris.myord.quantitypreordered
|
||||
if (qta > 1 || qta === 0)
|
||||
strprod = t('ecomm.prodotti')
|
||||
|
||||
if (qta > 0) {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//updateproduct()
|
||||
|
||||
//updateproduct()
|
||||
if (ris === null || ris.myord.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
|
||||
if (ris === null || ris.myord.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
|
||||
})
|
||||
return ris
|
||||
})
|
||||
},
|
||||
|
||||
getQuantityByOrder(order: IOrder): string {
|
||||
getQuantityByOrder($t: any, order: IOrder): string {
|
||||
let mystr = '';
|
||||
if (order.quantity > 0) {
|
||||
mystr += order.quantity
|
||||
}
|
||||
if ((order.quantitypreordered > 0) && (order.quantity > 0)) {
|
||||
mystr += ' ' + $t('ecomm.available')
|
||||
mystr += ' + '
|
||||
}
|
||||
if (order.quantitypreordered > 0) {
|
||||
mystr += ' Prenotata :' + order.quantitypreordered
|
||||
mystr += ' ' + order.quantitypreordered + ' ' + $t('ecomm.preord');
|
||||
}
|
||||
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