Aggiornamento modifiche preOrdini
This commit is contained in:
@@ -53,7 +53,12 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
},
|
||||
|
||||
getProduct: (state: IProductsState) => (code: string): IProduct => {
|
||||
getProductById: (state: IProductsState) => (id: string): IProduct => {
|
||||
const prod = state.products.find((prod: IProduct) => prod._id === id)
|
||||
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0, stockQty: 0, bookableQty: 0 }
|
||||
},
|
||||
|
||||
getProductByCode: (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,
|
||||
@@ -128,7 +133,7 @@ export const useProducts = defineStore('Products', {
|
||||
if (myord.items) {
|
||||
for (const item of myord.items) {
|
||||
if (item.order) {
|
||||
if (item.order.idProduct === idproduct) {
|
||||
if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) {
|
||||
totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0;
|
||||
}
|
||||
}
|
||||
@@ -141,14 +146,32 @@ 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) {
|
||||
const ris = state.orders.filter((ordercart: IOrderCart) => {
|
||||
return ordercart.items!.some(item => {
|
||||
if (item.order)
|
||||
return item.order.idProduct === idproduct
|
||||
return (item.order.idProduct === idproduct)
|
||||
&& (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)
|
||||
})
|
||||
})
|
||||
// console.log('Ordini ', ris)
|
||||
return ris ? ris : []
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err', e)
|
||||
}
|
||||
return []
|
||||
},
|
||||
|
||||
getOrdersCartInAttesaByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => {
|
||||
try {
|
||||
if (state.orders) {
|
||||
const ris = state.orders.filter((ordercart: IOrderCart) => {
|
||||
return ordercart.items!.some(item => {
|
||||
if (item.order)
|
||||
return (item.order.idProduct === idproduct)
|
||||
&& (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)
|
||||
})
|
||||
})
|
||||
// console.log('Ordini ', ris)
|
||||
@@ -447,11 +470,22 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
}
|
||||
|
||||
neworder = this.createOrderByProduct(product, order)
|
||||
|
||||
if (!order.idStorehouse) {
|
||||
if (product.storehouses.length === 1) {
|
||||
order.idStorehouse = product.storehouses[0]._id
|
||||
} else {
|
||||
order.idStorehouse = globalStore.storehouses ? globalStore.storehouses[0]._id : ''
|
||||
}
|
||||
}
|
||||
|
||||
if (order.idStorehouse) {
|
||||
neworder = this.createOrderByProduct(product, order)
|
||||
}
|
||||
}
|
||||
|
||||
if (neworder && !neworder.idStorehouse)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store')
|
||||
// if (neworder && !neworder.idStorehouse)
|
||||
// return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store')
|
||||
|
||||
console.log('addToCart', 'userid=', userStore.my._id, neworder)
|
||||
|
||||
@@ -594,6 +628,41 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
return ris
|
||||
},
|
||||
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')
|
||||
|
||||
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) {
|
||||
msg = t('ecomm.prodotto_tolto')
|
||||
} else {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//updateproduct()
|
||||
|
||||
if (ris === null || ris.myord.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
getQuantityByOrder(order: IOrder): string {
|
||||
let mystr = '';
|
||||
@@ -605,36 +674,6 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
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